[英]Meteor: get template name in spacebars
我開始開發流星webapp。 我使用帶有鐵路線的meteor和使用yield的主要layout.html文件。
在router.js我有:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});
Router.route('/login', {name: 'login'});
在layout.html中:
<template name="layout">
<div class="container">
{{> header}}
<main id="{{ actualLoadedTemplate }}">
{{> yield}}
</main>
</div>
</template>
我希望'main'標簽具有實際加載模板的id,在這種情況下為“login”。 有辦法實現嗎? 有什么建議? 謝謝
我剛想通了
Template.registerHelper('actualLoadedTemplate', function(){
return Router.current() && Router.current().route.getName().replace('.','-');
}
);
templateName = template.view.name.replace('Template.', '')
template
是Template.instance()
或this
在onCreated
, onRendered
, onDestroyed
回調
您可以在布局上定義模板助手:
Template.layout.helpers({
actualLoadedTemplate: function(){
return Router.current() && Router.current().template;
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.