小胡子中的部分/模板继承如何工作?

How does Partials / Template inheritance work in Mustache?

我不太理解从 Mustache/Hogan.js 继承的部分/模板。根据定义 here and here,您似乎必须有两个不同的文件才能使其工作。我在我的(客户端)页面中按如下方式使用它:

<template id="server-template"> {{#servers}} <b>some html and {{> some other which I dont understand how to use}}</b> {{/servers}} </template> <template id="room-template"> I want this in up there. (in the "partials" tag) </template>

感谢您的帮助。我用这个编译它们:

var source = $('#room-template').html(), compiled = Hogan.compile(source) $('#main').html(compiled.render(data))

这可能吗?

docs 声明您必须单独编译您的部分,然后将它们传递给 render 函数:

In mustache.js an object of partials may be passed as the third argument to Mustache.render. The object should be keyed by the name of the partial, and its value should be the partial text.

var roomTemplateSource = $('#room-template').html();
var roomTemplate = Mustache.compile(roomTemplateSource);
Mustache.render(template, view, {
  room: roomTemplate
});

<template id="server-template">
        {{#servers}}
        <b>some html and {{> room}}</b>
        {{/servers}}
</template>