【问题标题】:template naming for precompile预编译的模板命名
【发布时间】:2013-12-06 13:52:55
【问题描述】:

我正在使用 Grunt 和 Yeoman 为 ember 应用预编译我的车把模板。

在他们写的教程中:

<script type="text/x-handlebars" data-template-name="todos">
...
</script>

我有一个文件todos.hbs

现在我必须创建一个模板:

<script type="text/x-handlebars" data-template-name="todos/index">
</script>

我使用什么语法来创建todos/index .hbs 文件?

【问题讨论】:

    标签: ember.js handlebars.js yeoman yeoman-generator


    【解决方案1】:

    您的todos/index 是嵌套资源吗?

    在这种情况下,使用 Grunt,我将 todos.hbs 放在嵌套资源的父文件夹中,仅在其中渲染 {{outlet}}-tag 并将名为 index.hbstodos/index 放在名为 @987654327 的子文件夹中@。在这些模板中,我通常会省略 &lt;script type="text/x-handlebars" data-template-name="todos/index"&gt;...&lt;/script&gt; 部分,因为 Grunt 根据文件名识别它们。

    如果您的路线没有嵌套,您应该能够在没有子文件夹的情况下执行相同的操作。如果我错了,请纠正我

    这样做时,请务必将 Grunt 配置为监视子文件夹的更改。见this thread 我希望这会有所帮助

    【讨论】:

    • 查看@kingpin2k 的简短回答;)
    【解决方案2】:

    在模板目录下新建文件夹todos,并在其中创建index.hbs文件。

    【讨论】:

    • 好酷。我有点担心新目录会弄乱 Grunt,但看到它们仍然会被编译。在Gruntfile.jsemberTemplates: { files: '&lt;%= yeoman.app %&gt;/templates/**/*.hbs',
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多