私の Meteor アプリケーションでは、IronRouter を使用してセッション変数を動的に生成しているため、ルーターをロードするときに「after」ブロックの一部として使用しています。残念ながら、Session 変数は生成されず、pageTitle と Subtitles の動的な値は読み込まれません。ただし、奇妙なことに、ブラウザーコンソールからセッション変数を手動で設定すると機能します。
ここに私のルーターコードがあります:
this.route('dashboard'), {
path: '/dashboard',
after: function () {
Session.set('pageTitle', 'Dashboard');
Session.set('pageSubTitle', 'Welcome to your dashboard.');
}
};
私もこのイナ・ビフォア・ブロックを試しました。
ヘルパー関数は次のとおりです。
// Set title and subtitle values
Template.pageSetup.helpers({
pageTitle: function() {
return Session.get('pageTitle');
},
pageSubTitle: function() {
return Session.get('pageSubTitle');
}
});
レンダリングするテンプレートのブロックは次のとおりです。
<h3 class="title">
<i class="icon-dashboard"></i>
{{pageTitle}}
</h3>
<h5>
<span>
{{pageSubTitle}}
</span>
</h5>
助けてくれてありがとう。