I started to develop a meteor webapp. I use meteor with iron routes and a main layout.html file that use yield.
In router.js i have:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});
Router.route('/login', {name: 'login'});
In 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. 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;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.