2014-03-24 141 views
0

我有以下页面:铁路由器在静态情况下

main.html中

<html> 
<body> 
    <div> 
     [more static content] 
     <div id="content"></div> 
    </div> 
</body> 
</html> 

tpl1.html

<template name="something"> 
    [...] 
</template> 

而且我想用铁路由器将“something”模板填充到“content”div中。我无法找到一种路径路径来呈现只有一个div。我试着这样做:

<div id="content">{{yield}}</div> 

但始终结果是:

<html> 
<body> 
    <div> 
     [more static content] 
     <div id="content"></div> 
    </div> 
    [... content from "something" template ...] 
</body> 
</html> 

而不是:

<html> 
<body> 
    <div> 
     [more static content] 
     <div id="content">[... content from "something" template ...]</div> 
    </div> 
</body> 
</html> 

什么是我想要做的。

我的铁路由器配置为:

Router.map(function() { 
    this.route('principal',{ 
     path:"/someaction", 
     template:"something" 
    }); 

¿我如何能做到这一点?谢谢!

+2

你有没有试过* *

{{yield}}
'这样的东西,还是那个?这就是它应该做的! –

回答

2

你基本上拥有它。唯一的额外代码,您应该需要被添加{{yield}}到您的div:

<html> 
<body> 
    <div> 
     [more static content] 
     <div id="content">{{yield}}</div> 
    </div> 
</body> 
</html> 

如果你只是读下来iron-router github一点,你应该迅速找到一个伟大的部分谈论yield。你甚至可以使用多个。

0

的问题解决了,把main.html中的文字转换为模板:

<template name="main"> 
    <html> 
    <body> 
    <div> 
     [more static content] 
     <div id="content">{{yield}}</div> 
     </div> 
    </body> 
    </html> 
</template> 

,并在路由器:

this.route('principal',{ 
    path:"/someaction", 
    template:"something", 
    layoutTemplate:"main" 
}); 

这不是我想要的(因为现在的账户-ui不起作用),但它是:P。

如果有人知道如何做原始任务,它将是非常好的!