如何在渲染时设置 Meteor 模板标题?

How Do I Set Meteor Template Title On Render?

我有一行动态代码:

 <label>{{title}}</label>
//template name="header"

我正在使用 iron:router,该应用现在非常简单:

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

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

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

我想要一个不依赖于 Session 的解决方案来动态呈现 {{title}}

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

你们有什么优雅、超级简单的解决方案吗?

PS: 模板'header'在ApplicationLayout模板中。 ApplicationLayout 在 header.

下面有一个 {{> yield}}

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

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

Router.route("/scientific",{
  template:"scientific",
  title:"Scientific stuff"
});

然后您可以根据(反应式)当前路由控制器在您的 header 模板上定义标题助手。

Template.header.helpers({
  title:function(){
    return Router.current().route.options.title;
  }
});