首页 文章

使用meteor-router的布局

提问于
浏览
2

从这里讨论,

Allow a passed in variable to {} helper

我想在现有的{}中显示模板;

我的用例:我有一个非常简单的高级身体模板

<template name="body">
    {{> header}}
    {{> notifications}}

    <div class="content" id="content">
        <div id="main-content">

            {{{renderPage}}}

        </div>
    </div>
    {{> footer}}

</template>

正如您所看到的,我的主要内容是 {{renderPage}} . 当我设置一条路线时,这很有用:

'/home': 'home'

路径找到模板“home”并用该模板替换renderPage . 我想现在扩展它,看看路由模板是否可以放在特定的div中 .

例如,在我的home.html模板中:

<template name="home">
        {{#if isAdmin}}
                <h1>student</h1>
        {{/if}}
        <div id="inner_home">
                  {{renderPage innerHome}}
         </div>
</template>

是否有可能有一个不同的路线 /home/tools : 'home_tools 渲染它的模板不在最高主要内容div但在我的孩子div inner_home

编辑:

我正在评估一种方法,它只使用JQuery和meteor-router方法的回调函数来获取我正在寻找的模板并将其直接添加到相关的div标签中 .

就像是:

var foundTemplate = _.template($('#item-template').html())
  $('#div_example').html(foundTemplate); //

如果有人有更好的方法,请告诉我 .

1 回答

  • 0

    当然 .

    client.js

    Meteor.Router.add({
      '/home/tools': function() {
        Session.set("homeTemplate", "tools");
        return 'home';
      },
      '/home/admin': function() {
        Session.set("homeTemplate", "admin");
        return 'home';
      }
    });
    

    home.js

    Template.home.homeTemplateTools = function() {
        return Session.equal("homeTemplate", "tools");
    };
    
    Template.home.homeTemplateAdmin = function() {
        return Session.equal("homeTemplate", "admin");
    };
    

    home.html

    <template name="home">
        {{#if isAdmin}}
                <h1>student</h1>
        {{/if}}
        <div id="inner_home">
        {{#if homeTemplateTools}}
          {{> homeTools}}
        {{/if}}
        {{#if homeTemplateAdmin}}
          {{> homeAdmin}}
        {{/if}}
        </div>
    </template>
    

相关问题