貌似“字符串模板”这个术语不太准确。。。。
a = {'name':'World'} str = 'Hello %(name)s!' print str%a # Hello World!
总感觉直接用ejs之类的模板系统太重了。。。有没有轻量化一些的解决方案
在nodejs里,这种模板是如此之多 比较有名的是mustache https://github.com/janl/mustache.js ,以及他的强化版:handlebars http://handlebarsjs.com/
检索一下,会有很多
下面都是 atpl dust eco ect ejs haml haml-coffee handlebars hogan jade jazz jqtpl JUST liquor lodash mustache nunjucks QEJS ractive swig templayed toffee underscore walrus whiskers
— —。。。大家还没明白我的意思……我是觉得这样的模板系统太重了……有没有一些微量级的解决方案,我不是想要一个html模板……只是要在字符串中插入一些内容而已……
Node.js api 内置字符模板替换…
http://nodejs.org/api/util.html#util_util_format_format
需求是微量级的话,上面那个文档里头的直接用字符位置锚点,应该可以满足吧?
恩。。这个靠谱……多谢~
一直觉得underscore应该加一个format功能
点赞。。。大家快去fork吧。。。
mustache
有的
看http://www.csdn.net/article/2015-09-15/2825708-7-reasons-to-upgrade-to-node-v4?utm_source=tuicool
《升级到Node V4的七个理由 支持大量ES6特性》
Node V4就有增加模板字符串功能
es6就有模版字符串了
ES6有Template strings,nodejs 4.0+支持,其他版本加flag ES6 Template strings
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
在nodejs里,这种模板是如此之多 比较有名的是mustache https://github.com/janl/mustache.js ,以及他的强化版:handlebars http://handlebarsjs.com/
检索一下,会有很多
下面都是 atpl dust eco ect ejs haml haml-coffee handlebars hogan jade jazz jqtpl JUST liquor lodash mustache nunjucks QEJS ractive swig templayed toffee underscore walrus whiskers
— —。。。大家还没明白我的意思……我是觉得这样的模板系统太重了……有没有一些微量级的解决方案,我不是想要一个html模板……只是要在字符串中插入一些内容而已……
Node.js api 内置字符模板替换…
http://nodejs.org/api/util.html#util_util_format_format
需求是微量级的话,上面那个文档里头的直接用字符位置锚点,应该可以满足吧?
恩。。这个靠谱……多谢~
一直觉得underscore应该加一个format功能
点赞。。。大家快去fork吧。。。
mustache
有的
看http://www.csdn.net/article/2015-09-15/2825708-7-reasons-to-upgrade-to-node-v4?utm_source=tuicool
《升级到Node V4的七个理由 支持大量ES6特性》
Node V4就有增加模板字符串功能
es6就有模版字符串了
ES6有Template strings,nodejs 4.0+支持,其他版本加flag ES6 Template strings