2013-03-04 111 views
3

n00b這裏。我試圖將任意模板「注入」到另一個模板中。但是好像我做錯了:)流星:如何從模板助手返回模板?

whatever.html:

<template name="parent"> 
    {{child}} 
</template> 

<template name="child1"> 
    I'm child 1 
</template> 

<template name="child2"> 
    I'm child 2 
</template> 

whatever.coffee

x = "child1" 
Template.parent.child = -> Template[x](@) 

這將創建 「HTML註釋」(http://docs.meteor.com/#template_call)作爲結果,但{{child}}助手的輸出是html編碼的,因此不會被解釋。

我知道我可以使用Template.myTemplate.rendered事件來使用jQuery將模板直接添加到DOM。但是,這似乎是相當黑客imho。如果可能的話,我寧願幫助者生成。

什麼是「正確」的方式來做到這一點?是否有可能在模板中隱藏結果?反應性會起作用嗎?

預先感謝!! 1

問候

+1

爲什麼不在父項中使用'{{> child1}}'? – Akshat 2013-03-04 18:46:37

+0

我希望.coffee(或.js)文件決定要顯示哪個模板。如果我在whatever.html中使用'{{> child1}}',它將呈現'