簡體   English   中英

如何設置渲染的流星模板標題?

[英]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}}的方法的解決方案。

理想情況下,我想在路由器代碼中的某個位置定義該標題,然后讓我的標頭自動將其選中。 我不想在我的Template.rendered回調中做很多Session.set / get(我似乎在使用Semantic-UI復選框時遇到問題)。

你們有優雅,超簡單的解決方案嗎?

PS:模板“標頭”位於ApplicationLayout模板中。 ApplicationLayout在標題下方有一個{{> yield}}

一個可行的選擇是將您的標題存儲在路線選項中,如下所示:

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

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

然后,您可以基於(反應性)當前路徑控制器在標題模板上定義標題助手。

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