2016-04-10 120 views
0

我有这样的HomeLayout.html:流星Iron.Router动态模板

<template name="HomeLayout"> 
    <main> 
    {{>Template.dynamic template=main}} 
    </main> 
</template> 

而一个LoginLayout.html这样的:

<template name="LoginLayout"> 
    <main> 
    <p> Login Layout Test </p> 
    </main> 
</template> 

我想里面输入HomeLayout这LoginLayout 。 要启动HomeLayout我用这个代码:

Router.route('/', function() { 
    this.render('HomeLayout'); 
}); 

但我不知道我怎么可以加载内部HomeLayout这LoginLayout ...

回答

1

只是定义返回要动态插入模板帮助:

Template.HomeLayout.helpers({ 
    main: function(){ 
    return "LoginLayout"; 
    } 
}); 

如果你有{{>Template.dynamic template=main}}上述助手将评估main作为帮助,这将返回你正在寻找的布局。

但我不知道你的<main></main>标签在做什么。

+0

不能使用{{> yield}}工作,并使用当前路由名称查找匹配的模板? –

+0

@JanJoukeTjalsma是的,但动态模板通常不受i-r控制,它们由提供传递给动态模板的变量控制。动态模板提供了对'{{> yield}}'的额外控制,例如,当您想要跨模板共享事件映射时,它非常有用。 –