【发布时间】:2012-11-02 01:37:23
【问题描述】:
我正在尝试创建一个简单的应用程序来将 mustache 模板编译到服务器端的静态页面中,这是我目前所得到的:
var view = {
title: "Joe",
calc: function () {
return 2+4;
}
};
var mustache = require("mustache");
var template = require("./home.template");
var output = mustache.to_html(template, view);
console.log(output);
我的模板看起来像:
{{title}} spend {{calc}}
关于是什么导致此失败的任何建议?
这是完整的错误信息:
home.template:1
} spend {{calc}}
^
module.js:437
var compiledWrapper = runInThisContext(wrapper, filename, true);
^
SyntaxError: Unexpected token {
at Module._compile (module.js:437:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/Users/MorehouseJ09/Documents/production_development/mustache/current/compiler.js:12:16)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
任何帮助都会很棒!
【问题讨论】:
-
错误信息是什么?你已经写了一份声明。
-
嗯,它没有做我想要的。编译后的包装器是什么意思?我正在尝试将 html 输出到终端
-
它输出什么?那句话是字面意思吗?
-
刚刚更新了错误信息...感谢您的帮助
-
我不熟悉 Mustache。你确定可以给它提供函数值吗?
标签: javascript node.js npm mustache