有没有办法只渲染部分?

is there a way to render only the partials?

有没有办法只渲染局部?

例如 header 部分和 home.mustache 包含的 footer 部分将生成 home-all.mustache

是的!只需更改 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;
};

现在它将只输出部分解析到一个模板中。