有没有办法只渲染部分?
例如,header
包含的footer
部分和home.mustache
部分将生成home-all.mustache
答案 0 :(得分:0)
prototype
即可
var Mustache = require('mustache');
Mustache.Writer.prototype.renderTokens = function (tokens, context, partials, originalTemplate) {
var buffer = '';
var token, symbol, value, tag;
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
value = undefined;
token = tokens[i];
symbol = token[0];
tag = value = mustache.tags[0] + token[1] + mustache.tags[1];
if (symbol === '#') value = this._renderSection(token, context, partials, originalTemplate);
else if (symbol === '^') value = this._renderInverted(token, context, partials, originalTemplate);
else if (symbol === '>') value = this._renderPartial(token, context, partials, originalTemplate);
else if (symbol === '&') value = tag;
else if (symbol === 'name') value = tag;
else if (symbol === 'text') value = this._rawValue(token);
if (value !== undefined)
buffer += value;
}
return buffer;
};
现在它将输出只有部分解析为一个模板。