【问题标题】:How to add templates in meteor?如何在流星中添加模板?
【发布时间】:2018-04-27 05:08:18
【问题描述】:

我正在学习流星框架。我正在尝试渲染模板,但它会引发此错误:

Errors prevented startup:

While processing files with static-html (for target web.browser):
client/html/sidebar.html:1: Expected <head> or <body> tag

我的 layout.html 文件是这样的:

<body>

    {{> sidebar}}

</body>

sidebar.html 文件是这样的:

<template name="sidebar">
        <h1>Hello</h1>
</template>

为什么它不在 layout.html 上呈现??

【问题讨论】:

    标签: meteor meteor-blaze


    【解决方案1】:

    用一个名为“layout”的模板(例如)替换你的 body 标签,并使这个模板成为你路由器配置中的 layoutTemplate。

    <template name="layout">
    
      {{> sidebar}}
    
      {{> yield}}
    
    </template>
    

    以 IronRouter 为例:

    Router.configure({
      layoutTemplate: 'layout'
    });
    

    【讨论】:

    • 我必须在哪里添加到 router.configure??
    • /lib 文件夹中文件的任何位置。我称我的文件为“router.js”。请确认您使用的是 IronRouter。我相信项目默认使用 FlowRouter。在那种情况下,我不知道如何配置您的路由器。
    【解决方案2】:

    看起来您的问题是您使用的是static-html 包而不是blaze-html-templates,这意味着不会处理所有模板代码

    做:

    meteor remove static-html
    meteor add blaze-html-templates
    

    在你的项目文件夹中看看是否有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      相关资源
      最近更新 更多