与 consolidate.js 一起使用时,我无法像 {{>my_partial}} 那样添加小胡子阅读部分。我从以下内容开始我的快速应用程序:
文件 index.js:
var express = require('express'),
cons = require('consolidate');
app.configure(function(){
app.set( 'models', BACKEND + '/models' ); // Set the models directory
app.set( 'views', BACKEND + '/views' ); // Set the views directory
app.set( 'controllers', BACKEND + '/controllers' ); // Set the controllers dir
app.set( 'view engine', 'html' ); // Set Mustache as the templating engine
app.engine( 'html', cons.mustache );
app.engine( 'mustache', cons.mustache );
app.use( app.router ); // Set the router
app.use( '/public', express.static( BASEPATH + '/frontend/public' ) ); // set frontend/public to /public for users
app.use( '/js', express.static( BASEPATH + '/frontend/js' ) );
app.use( '/out', express.static( BASEPATH + '/out' ) ); // documentation path
// Set client side libraries here (Make them available to the public based on settings.json)
for(setting in SETTINGS.public) {
app.use( SETTINGS.public[setting], express.static(BASEPATH + SETTINGS.public[setting]) );
}
});
然后,在控制器的某个地方,我像这样使用渲染:
function Blog(app, request, response){
var fs = require('fs'),
Blog = require( app.get('models') + '/blog' ),
model = new Blog(),
scripts = fs.readFileSync( VIEWS + '/m_scripts.mustache').toString() ;
model.List(function(data){
response.render('layout',
{
title : 'My Blog',
body : 'Hello Mustache World',
list : data.rows,
cache : false,
partials : {
m_scripts : partialStr
}
}
);
});
};
exports.list = Blog;
m_scripts.mustache 有:
<script data-src="ergierjgoejoij"></script>
布局模板渲染得很好,参数也很好地传递,部分 m_scripts 与 readFileSync().toString() 传递的文本一起传递,但 HTML 内容被编码并呈现无用。
我的问题是,有没有一种方法可以只放入 layout.mustache {{>m_scripts}} 并且 mustache 可以自动加载 m_scripts.mustache 而无需将其传递给 render()。如果没有,我错过了什么?