2

我想将 mustache 与 node 一起使用,但由于某些原因,partials 不起作用:我已经创建了 2 个文件,app.js并且test.mustache,它们都在同一个目录中。使用package.json文件和 npm 我已经为这个项目安装了最新版本的 mustache。文件如下所示:

应用程序.js:

var mus = require('mustache');
console.log(mus.render('test.mustache: {{>test}}'));

test.mustache:

This is a test

如果我运行,node app.js我希望得到以下输出:test.mustache: This is a test,但我只是得到:test.mustache:

其他 mustache 标签确实按预期工作,甚至 mustache 的 vows 测试也不会报告任何错误。

我应该怎么做才能让它正常工作?

4

2 回答 2

6

使用节点检查器,我用 Mustache 调试了上述应用程序。事实证明,Mustache 不会自动包含部分文件,这与手册所暗示的相反(向下滚动到部分文件)。相反,您总是需要手动提供部分作为 render 方法的第三个参数。

于 2012-08-13T14:53:40.067 回答
0

仅供参考,此版本的 Consolidate.js 支持部分:https ://github.com/simov/consolidate.js

Consolidate 使在 Express.js 中使用许多模板引擎变得容易

于 2012-12-22T22:51:46.507 回答