简体   繁体   English

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

[英]How Do I Set Meteor Template Title On Render?

I have a dynamic line of code: 我有一个动态的代码行:

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

I'm using iron:router, the app is super simple right now: 我正在使用iron:router,该应用程序现在非常简单:

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

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

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

I'd like a solution that doesn't rely on Session as a way to dynamically render the {{title}} . 我想要一种不依赖Session作为动态呈现{{title}}的方法的解决方案。

Ideally I'd like to define this title somewhere in my router code, and just have my header automatically pick it up. 理想情况下,我想在路由器代码中的某个位置定义该标题,然后让我的标头自动将其选中。 I don't particularly want to do a lot of Session.set/get over in my Template.rendered callbacks (I seem to get an issue doing this with Semantic-UI checkboxes). 我不想在我的Template.rendered回调中做很多Session.set / get(我似乎在使用Semantic-UI复选框时遇到问题)。

Do you guys have any elegant, super simple solutions? 你们有优雅,超简单的解决方案吗?

PS: the template 'header' is in the ApplicationLayout template. PS:模板“标头”位于ApplicationLayout模板中。 The ApplicationLayout has a {{> yield}} below the header. ApplicationLayout在标题下方有一个{{> yield}}

A viable option is to store your title inside your route options like this : 一个可行的选择是将您的标题存储在路线选项中,如下所示:

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

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

Then you can define a title helper on your header template based on the (reactive) current route controller. 然后,您可以基于(反应性)当前路径控制器在标题模板上定义标题助手。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM