代码之家  ›  专栏  ›  技术社区  ›  Imaky tvanfosson

静态环境中的铁路由器

  •  0
  • Imaky tvanfosson  · 技术社区  · 11 年前

    我有以下页面:

    main.html

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

    第1页.html

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

    我想使用Iron router将“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 回复  |  直到 11 年前
        1
  •  2
  •   Firo    11 年前

    你基本上拥有它 应该 需要添加 {{yield}} 进入您的div:

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

    如果你只是把 iron-router github 你应该很快找到一个很棒的部分 yield 。您甚至可以使用多个。

        2
  •  0
  •   Imaky tvanfosson    11 年前

    问题解决了,将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。

    如果有人知道如何完成最初的任务,那就太棒了!