【问题标题】:Adding swig as template engine to keystoneJS将 swig 作为模板引擎添加到 keystoneJS
【发布时间】:2014-07-03 17:46:54
【问题描述】:

我已将 swig 作为模板引擎添加到我的 KeystoneJS 项目中,但它不会加载我的模板。我已将以下内容添加到我的 keystone.js 文件中:

// Require keystone
var keystone = require('keystone');
var swig = require('swig');

// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
// and documentation.

keystone.init({

    'name': 'it_blog',
    'brand': 'it_blog',

    'less': 'public',
    'static': 'public',
    'favicon': 'public/favicon.ico',
    'views': 'templates/views',
    'view engine': 'swig',
    'custom engine': swig.renderFile,
    'auto update': true,
    'session': true,
    'auth': true,
    'user model': 'User',
    'cookie secret': '*omitted*'

}); 

这是我得到的 node.js 错误:

Error thrown for request: /
Error: Failed to lookup view "index"
  at Function.app.render    (/Users/admin/Desktop/Development/my_project/node_modules/keystone/node_modules/express/lib/application.js:495:17)

我按照此处列出的步骤操作:https://github.com/JedWatson/keystone/issues/270

【问题讨论】:

  • Express 用文件扩展名做了一些疯狂的事情。是否自动尝试查找index.swig,但您的文件是index.html
  • @PaulArmstrong 使用 .swig 文件不走运

标签: javascript node.js template-engine swig-template keystonejs


【解决方案1】:

Yeoman 的官方 Keystone Generator 现在包括 Swig 支持和示例模板,我建议使用它来启动项目,选择 swig 作为模板引擎,并复制其实现。

开始使用生成器的说明在这里:http://keystonejs.com/getting-started/

【讨论】:

  • 太棒了!谢谢杰德。这是对已经很棒的 KeystoneJS 包的一个很好的补充。
猜你喜欢
  • 1970-01-01
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-03
  • 2019-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多