我想更改默认 Swig tagControls {% ... %} 到 {? ...?} 我正在使用 sails.js 框架。
我将 swig.js 文件添加到配置文件夹,其中包含:
module.exports.swig = {
SwigOpts: {
'tagControls': ['{?', '?}']
}
};
但是不行,在浏览器中查看是这样的:
{? for user in users ?}
{? user.email ?}
{? endfor ?}
因此,标签没有被解释。我的配置文件错了吗?标准标签 {% ... &} 工作正常。
最佳答案
像这样的东西应该可以工作:在你的 config/views.js
engine: {
ext: 'swig', // Or `html`, whatever you are using
fn: function (pathName, locals, cb) {
var swig = require('swig');
swig.setDefaults({tagControls: ['{?', '?}']});
return swig.renderFile(pathName, locals, cb);
}
},
至于 config/swig.js
和 module.exports.swig
,我认为它不会被自动处理。
关于node.js - Swig 模板引擎和 Sails.js - 如何更改 tagControls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21830397/