javascript - 有什么好用的JS模板引擎吗?
天蓬老师
天蓬老师 2017-04-10 16:27:49
[JavaScript讨论组]

有什么好用的JS模板引擎吗?
比如说 handlebars
或者 augularjs 这些的模板引擎,个人感觉都不是特别好用啊

有没有什么比较好用的模板引擎?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(19)
伊谢尔伦

试一下artTemplate

PHP中文网

LinkedIn把他们转template engine的经验给blog了下来,
post里边的数据可能已经outdated了,不过还是很有參考价值的,楼主可以参考一下:
The client-side templating throwdown: mustache, handlebars, dust.js, and more

他们的测评准则:

  • DRY: how DRY is the templating technology? is there support for code-reuse and partials?

  • i18n: is there support for translations and multiple languages?

  • Hot reload: are changes visible immediately or is there a compile/deploy cycle?

  • Performance: how long does it take to render in the browser and server?

  • Ramp-up time: how is the learning curve?

  • Ramped-up productivity: once you've ramped-up, how fast can you build things?

  • Server/client support: can the same template be rendered both client-side and server-side?

  • Community: is there an active community using this project? Can you google issues?

  • Library agnostic: are there dependencies on other JS libraries, such as jQuery or Mootools?

  • Testable: how hard is it to write unit and integration tests?

  • Debuggable: is it possible to step through the code while it's running to track down errors?

  • Editor support: is there an editor with auto-complete, syntax highlighting, error checking, etc?

  • Maturity: is this a relatively stable project or still experimenting and churning?

  • Documentation: how is the documentation?

  • Code documentation: do the templates encourage/require documentation/comments?

个人比较常用handlebars,因为不想view里面有太多logical的东西,
而且HBS可以precompile,还可以自由选择在server或是client side render
最后就是handlebars跟jq一点关系都没有..

ringa_lee

dot.js 速度快,这是有评测数据的,同时支持在模版中加入js语法。

阿神

vue.js 国人做的框架 和angular类似 不过精简了很多。中文文档非常全。

高洛峰

如果纯用模板的话,推荐doT,速度快,支持编译成函数。如果想高级的推荐 riotjs 2.0 、react, 这两个是 webcomponent 概念了,比模板更高级点。

伊谢尔伦

我也是刚接触AngularJS,觉得用起来还不是很熟练,与以前用的Jquery等都不一样,但是AngularJS在当下来说是非常流行的,它的确少去了像Jquery的DOM操作。其实每一个框架或模版都有优劣,也没有所谓的好用或不好用,只有熟不熟练!

ringa_lee

10 BEST JAVASCRIPT TEMPLATE ENGINES FOR DEVELOPERS

自取所需!

怪我咯

如果你的业务不是极端注重效率,推荐nunjucks。

java,python,node三种语言的许多模板我都用过,还是觉得python中jinja2的设计最舒服,nunjucks是模仿的jinja2,虽然模拟的不彻底,但是也很不错了。

(swig和nunjucks差不多,而且语法的容错性比nunjucks稍好,虽然效率稍差一丁点,但是因为很久不更新了,不建议了就;
其实这两种模板相当于给jinja2做了个旁证,如果设计不好,也不会不约而同都去模仿~~)

黄舟

arttemplate

伊谢尔伦

推荐一个我觉得很牛逼的riotjs,你看看它1.x的版本里面有个简洁的模板实现,大概就10行左右的代码

riot.render = function(tmpl, data, escape_fn) {
    if (escape_fn === true) escape_fn = default_escape_fn;
    tmpl = tmpl || '';
    return (FN[tmpl] = FN[tmpl] || new Function("_", "e", "try { return '" +
        tmpl.replace(/[\\\n\r']/g, function(char) {
            return template_escape[char];
        }).replace(/{\s*([\w\.]+)\s*}/g, "' + (e?e(_.$1,'$1'):_.$1||(_.$1==undefined?'':_.$1)) + '") + "' } catch(e) { return '' }")
    )(data, escape_fn);
};
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号