Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor:在空格键中获取模板名称_Javascript_Meteor_Iron Router_Spacebars - Fatal编程技术网

Javascript Meteor:在空格键中获取模板名称

Javascript Meteor:在空格键中获取模板名称,javascript,meteor,iron-router,spacebars,Javascript,Meteor,Iron Router,Spacebars,我开始开发meteor网络应用程序。我将meteor与iron routes一起使用,并使用使用yield的main layout.html文件。 在router.js中,我有: Router.configure({ layoutTemplate: 'layout', loadingTemplate: 'loading' }); Router.route('/login', {name: 'login'}); 在layout.html中: <template name="la

我开始开发meteor网络应用程序。我将meteor与iron routes一起使用,并使用使用yield的main 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.layout.helpers({
  actualLoadedTemplate: function(){
    return Router.current() && Router.current().template;
  }
});
我刚想出来

Template.registerHelper('actualLoadedTemplate', function(){
    return Router.current() && Router.current().route.getName().replace('.','-');
  }
);

templateName=template.view.name.replace('template','')


template
template.instance()
onCreated
onRendered
onestroyed
回调中刚刚尝试过,但返回总是未定义的。可能是因为在加载的视图之外调用了辅助对象?