2014-03-24 138 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。

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