流星动态模板不起作用 [英] Meteor Dynamic Template not working

查看:100
本文介绍了流星动态模板不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{{> Template.dynamic template = content}}行使我的页面无法加载.实际上,有时它会使我的浏览器崩溃.我让它工作了一段时间,但是发生了一些事情,现在它不再工作了. {{> Template.dynamic template ='navBar'}}可以正常工作,所以我的包裹应该没问题.

The line {{> Template.dynamic template=content }} makes my page not load. It actually crashes my browser sometimes. I had it working for a while but something happened and now it does not work anymore. {{> Template.dynamic template='navBar' }} works so my packages should be ok.

流星:1.4 软件包:kadira:flow-router,kadira:blaze-layout

Meteor: 1.4 Packages: kadira:flow-router, kadira:blaze-layout

imports/ui/layouts/mainLayout.html:

imports/ui/layouts/mainLayout.html:

<template name="mainLayout">
  <header>
    <div class="container">
      {{> navBar }}
    </div>
  </header>
  <body>
    <div class="container">
      {{> Template.dynamic template=content }} <!-- not working -->
    </div>
  </body>
  <footer>
    <div class="container">
      <h3>Footer</h3>
    </div>
  </footer>
</template>

imports/ui/layouts/mainLayout.js:

imports/ui/layouts/mainLayout.js:

import { Template } from 'meteor/templating';
import './mainLayout.html';
import '../components/navBar.html';
import '../pages/settings.html';

imports/startup/client/routes.js:

imports/startup/client/routes.js:

import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import '../../ui/layouts/mainLayout.js';
import '../../ui/pages/settings.js';

FlowRouter.route('/', {
  action() {
    BlazeLayout.render('mainLayout', { content: 'mainLayout' });
  },
});

FlowRouter.route('/settings', {
  action() {
    BlazeLayout.render('mainLayout', { content: 'settings' });
  },
});

imports/ui/pages/settings.html:

imports/ui/pages/settings.html:

<template name="settings">
  <div class="container">
    <h1>This is the settings page</h1>
  </div>
</template>

推荐答案

此路线:

FlowRouter.route('/', {
  action() {
    BlazeLayout.render('mainLayout', { content: 'mainLayout' });
  },
});

无效,因为您正在将mainLayout组件插入自身-嵌套的content助手是问题所在.相反,您应该在content中渲染另一个组件:

is not going to work because you are inserting the mainLayout component into itself - the nested content helper is the issue. Instead, you should be rendering a different component into content:

BlazeLayout.render('mainLayout', { content: 'home' }); // or whatever component should be at "/"

这篇关于流星动态模板不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆