[英]Meteor: get template name in spacebars
I started to develop a meteor webapp. 我开始开发流星webapp。 I use meteor with iron routes and a main layout.html file that use yield.
我使用带有铁路线的meteor和使用yield的主要layout.html文件。
In router.js i have: 在router.js我有:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});
Router.route('/login', {name: 'login'});
In layout.html: 在layout.html中:
<template name="layout">
<div class="container">
{{> header}}
<main id="{{ actualLoadedTemplate }}">
{{> yield}}
</main>
</div>
</template>
I would that the 'main' tag, have the id of the actual loaded template, "login" in this case. 我希望'main'标签具有实际加载模板的id,在这种情况下为“login”。 Is there a way to accomplish that?
有办法实现吗? Any advice?
有什么建议? Thanks
谢谢
I just figured it out 我刚想通了
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
回调
You can define a template helper on your layout : 您可以在布局上定义模板助手:
Template.layout.helpers({
actualLoadedTemplate: function(){
return Router.current() && Router.current().template;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.