2013-04-08 108 views
3

我正在使用grunt-ember-templates预编译我的模板。正如预期的那样,该工具将我的模板放入Ember.TEMPLATES阵列中。我正在调整grunt-ember-templates的配置。为此,我想知道Ember.TEMPLATES阵列中的预期关键点是什么。比方说,我有这样的模板:给定数据模板名称的匹配模板名称

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

目前,我有一个名为app/templates/phones_index.hbs文件这个模板,并grunt-ember-templates是把预编译模板Ember.TEMPLATES["app/templates/phones_index"],但这是错误的。

data-template-name="phones/index"的预期关键是什么?

+1

我相信你应该编译应用程序/ templates'目录的'内容,而忽略在文件名中的目录部分,所以你不要将它翻译成模板名称。理想情况下'phones/index.hbs'应该翻译成'App.TEMPLATES [“phones/index”]'。请注意'_'用于部分(例如:'phones/_form.hbs',用于连接到电话资源的通用表单),所以在部分模板以外的模板中使用它可能不是一个好主意。我不是Grunt tho上最好的人,所以我不能说你应该怎么做。 – MilkyWayJoe 2013-04-08 19:54:54

回答

4

在你的例子中,Ember.TEMPLATES中的密钥应该是“phones/index”。

可以配置咕噜-烬模板砸你的路径的第一部分和app/templates/后留下的一切,这将给你正确的密钥假设你把你的模板文件app/templates/phones/index.hbs内。使用此设置,app/templates/phones/index.hbs文件的密钥将为Ember.TEMPLATES['phones/index'],这与具有data-template-name="phones/index"的未编译的<script>标记相同。

Gruntfile.js(相同Gruntfile.js在this项目):

ember_templates: { 
    options: { 
    templateName: function(sourceFile) { 
     return sourceFile.replace(/app\/templates\//, ''); 
    } 
    }, 
    'dependencies/compiled/templates.js': ["app/templates/**/*.hbs"] 
}, 
+0

比我想象的更简单+1 – MilkyWayJoe 2013-04-08 20:11:33

+0

谢谢。然后,我会将所有与手机相关的模板放在“app/templates/phones”目录中。但后来我遇到了一个问题:在哪里放置与data-template-name =“phone”'相关的模板,或者放到'data-template-name =“phone/edit”'? – dangonfast 2013-04-08 20:14:25

+0

另一个问题:你说“这与使用data-template-name =”phones/index“”的未编译的