今天搜索一堆模板的时候注意到还有这个术语, 就搜了下: The Case Against Logic-less Templates What's the advantage of Logic-less template (such as mustache)? Cult of Logic-Less Templates mustache -- Logic-less templates 然后... 英文都好难懂啊
比如 Mustache, 移除了 for if 等等语句,
用变量的值直接表示 if 执行的逻辑:
Shown.
{{#nothin}}
Never shown!
{{/nothin}}
以及自动对数据进行替换: Template:
{{#repo}}
<b>{{name}}</b>
{{/repo}}
Hash:
Data:
{
"repo": [
{ "name": "resque" },
{ "name": "hub" },
{ "name": "rip" },
]
}
Output:
<b>resque</b>
<b>hub</b>
<b>rip</b>
或者更花哨一些的,, 其实还是在实现 ejs 里的 for if 等等功能,
这样的方案看不出这个取舍带来特别的好处啊,
仅仅是模板的性能提升么? 但最快的 doT 也是能潜入 JS 代码的呀?
或者说 Logicless template 适用什么样的场景, Node 社区里会这么热?
回复 (3)
H
我觉得 Logic-less templates 也就是如同其字面意思吧。 在模板里码上一堆逻辑,有点混乱了,本身模板就是为了解决数据渲染的,而并不解决逻辑处理吧,况且维护会很痛苦的。
Y
话说,undersocre 那个模板引擎有用过没...?
J
引用 youxiachai话说,undersocre 那个模板引擎有用过没...?
就玩了下,看评测效率不是很高,除了引入外部代码的体积以外没发现特别的优势啊。
参与回复
登录后即可参与回复。登录