2015-01-05 12 views
1

我真的不明白Moustache/Hogan.js的partials/template继承。如定义herehere你似乎必须有两个不同的文件才能工作。我用它作为我的(客户端)页面如下:部分/模板继承在Mustache中如何工作?

<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))

是,即使可能吗?

回答

0

,你必须单独编译你的泛音,然后将它们传递给render功能docs状态:

在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> 
+1

非常感谢:) – kurtextrem