仔细看了Mustache中的partials的用法:
base.mustache:
<h2>Names</h2> {{#names}} {{> user}} {{/names}}
user.mustache:
<strong>{{name}}</strong>
但是实际使用中总是无法成功,会报错:
var Mustache = require( 'mustache' ); Mustache.render( Fs.readFileSync( './base.mustache', { users: [ { name: 'neekey' } ] ) );
其中user.mustache 和 base.mustache在同一目录下
求指正!
如果单纯用文本写的话,应该按照下面的格式
如果从文件中去读取
render第三个参数传入的对象的key值要和
{{> next_more}}
模版中的next_more一致原文是这么说的:
In mustache.js an object of partials may be passed as the third argument to
Mustache.render
. The object should be keyed by the name of the partial, and its value should be the partial text.详情参考: https://github.com/janl/musta...