繁体   English   中英

在Mustache中,部分/模板继承如何工作?

[英]How does Partials / Template inheritance work in Mustache?

我不是很了解Mustache / Hogan.js的局部/模板继承。 如此此处所定义,您似乎必须具有两个不同的文件才能使该工作正常进行。 我在(客户端)页面中按如下方式使用它:

<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函数:

在mustache.js中,部分对象可以作为第三个参数传递给Mustache.render。 该对象应以部分名称作为关键字,其值应为部分文本。

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM