【问题标题】:Meteor Dynamic Template not working流星动态模板不起作用
【发布时间】:2017-03-03 23:31:59
【问题描述】:

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

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

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:

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

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:

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

【问题讨论】:

  • 所以您是在布局中放置布局? BlazeLayout.render('mainLayout', { content: 'mainLayout' });

标签: meteor meteor-blaze


【解决方案1】:

这条路线:

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

不起作用,因为您将 mainLayout 组件插入到自身中 - 嵌套的 content 帮助器是问题所在。相反,您应该将不同的组件渲染到content

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

【讨论】:

  • 我对文件进行了一些重命名,但我的大脑在此过程中停止工作。谢谢你。它有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-25
  • 2015-11-18
  • 1970-01-01
  • 2018-03-03
  • 1970-01-01
  • 2015-02-08
相关资源
最近更新 更多