node.js - Swig 模板引擎和 Sails.js - 如何更改 tagControls

标签 node.js sails.js swig-template

我想更改默认 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.jsmodule.exports.swig,我认为它不会被自动处理。

关于node.js - Swig 模板引擎和 Sails.js - 如何更改 tagControls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21830397/

相关文章:

javascript - Nightmare.js 不适用于 Azure Webjob

Sails.js 在生产环境中重定向到 example.com

node.js - 注销并获取 new/csrfToken 后 SailsJS CSRF 不匹配

mysql - 水线 - 字段总和的位置

node.js - 将文档字段呈现为 HTML

node.JS Express Passport 路由

node.js - 当我提交时如何获取 git commit 消息?

javascript - 如何在 Javascript 中正确设置 Cassandra 客户端?

node.js - Node HTTP/2 设置托管证书的正确位置

javascript - Node + Express + Swig/将本​​地 json 文件传递​​给模板