1

我已經將swig添加爲我的KeystoneJS項目的模板引擎,但它不會加載我的模板。我已經添加了以下到我的keystone.js文件:將swig作爲模板引擎添加到keystoneJS

// 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

+0

快遞做一些瘋狂的事情與文件擴展名。它會自動試圖找到'index.swig',但你的文件是'index.html'? –

+0

@PaulArmstrong沒有運氣使用.swig文件 – RandomDeduction

回答

0

的Yeoman官方Keystone Generator現在包含Swig支持和示例模板,我推薦使用它來啓動項目,選擇swig作爲模板引擎,並複製其實現。

說明開始使用發電機的位置:http://keystonejs.com/getting-started/

+0

非常好!謝謝傑德。這對已經非常棒的KeystoneJS軟件包是一個很好的補充。 – RandomDeduction