【问题标题】:MeteorJS template placeholderMeteorJS 模板占位符
【发布时间】:2015-05-10 09:05:13
【问题描述】:

我开始使用 MeteorJS/Iron Router/Blaze,我正在尝试弄清楚如何为模板设置占位符。

我有一个菜单和一个页脚,它们只会部分改变,但它们之间是应该基于当前路线的主要内容。关键是我需要某种指针,比如有角度的“ng-view”。

例如。

<menu></menu>
{{some sort of placeholder}}
<footer></footer>

在路由器中:

Router.route('/', function () {

//render some template exactly into placeholder, dont append it to the bottom

});

也许我对meteorjs模板的理解有问题,我只是将我解决这个问题的方法建立在角度模板上。

【问题讨论】:

    标签: javascript meteor template-engine


    【解决方案1】:

    不确定我是否收到了您的问题,但这里有一个答案:

    您可以使用{{&gt; yield}} 标签来做到这一点。它将定义一个动态区域,该区域将显示与当前路线对应的视图

    您还可以像您一样为整个应用“设计”布局,例如layout.html

    <template name="layout">
      <div class="container">
      <header class="navbar">
        <div class="navbar-inner">
          <a class="brand" href="{{pathFor 'home'}}">My app</a>
        </div>
      </header>
      <div id="main" class="row-fluid">
        {{> yield}}
      </div>
      </div>
    </template>
    

    并告诉 Iron-Router 你的应用必须适合这个布局:

    Router.configure({
      layoutTemplate: 'layout'
    });
    
        // Then just define your routes
    
    Router.map(function() {
      this.route('home', {path: '/'});
    });
    

    你可能注意到我在布局中使用了{{pathFor 'home'}}。 Iron Router 允许您使用路由“名称”,因此如果您更改 URL,它不会做任何事情。

    我建议你读一本名为Discover Meteor 的好书!

    【讨论】:

    • 就是这样,我并没有考虑“组合”模板的最终视图,而只是考虑注入模板,这是我的错误。我刚刚发现更复杂的solution,这可能符合我的需要,但你的也可以:)
    猜你喜欢
    • 2015-05-20
    • 2012-02-17
    • 2020-09-18
    • 1970-01-01
    • 2019-06-15
    • 2020-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多