如何在渲染上设置流星模板标题?

ilr*_*ein 1 javascript meteor iron-router spacebars

我有一个动态的代码行:

 <label>{{title}}</label>
//template name="header"
Run Code Online (Sandbox Code Playgroud)

我正在使用铁:路由器,该应用程序现在非常简单:

Router.configure({
  layoutTemplate: 'ApplicationLayout'
})

Router.route('/', {
  template: "home"
})

Router.route('/scientific', {
  template: "scientific"
})
Run Code Online (Sandbox Code Playgroud)

我想要一个不依赖于Session动态渲染方式的解决方案{{title}}.

理想情况下,我想在我的路由器代码中的某处定义此标题,并让我的标题自动获取它.我不是特别想在我的Template.rendered回调中做很多Session.set/get over(我似乎在使用Semantic-UI复选框时遇到了这个问题).

你们有没有优雅,超级简单的解决方案?

PS:模板'header'位于ApplicationLayout模板中.ApplicationLayout {{> yield}}的标题下方.

sai*_*unt 6

一个可行的选择是将您的标题存储在您的路线选项中,如下所示:

Router.route("/",{
  template:"home",
  title:"Welcome Home !"
});

Router.route("/scientific",{
  template:"scientific",
  title:"Scientific stuff"
});
Run Code Online (Sandbox Code Playgroud)

然后,您可以基于(无效)当前路径控制器在标题模板上定义标题帮助器.

Template.header.helpers({
  title:function(){
    return Router.current().route.options.title;
  }
});
Run Code Online (Sandbox Code Playgroud)