grunt-contrib-handlebars配置问题

时间:2014-03-19 15:51:29

标签: javascript gruntjs handlebars.js

我对" grunt-contrib-handlebars"的配置存在问题,下面是我的设置。

handlebars: {
    compile: {
        options: {
            namespace: "my.namespace"
        },
        files: {
            "<%= dist %>/templates/templates.js": "<%= src %>/templates/*.handlebars"
        }
    }
}

这就是我现在所得到的:

my.namespace [&#34; SRC /模板/ baseTemplate.handlebars&#34;]

这就是我想要的:

my.namespace [&#34; baseTemplate&#34;]

所以我可以这样调用模板:

my.namespace.baseTemplate(templateObj);

有可能得到这个吗?

1 个答案:

答案 0 :(得分:0)

看看我的解决方案

enter image description here

我用browserify实现了它。

  1. 我生成了一个包含我所有模板的.js文件。
  2. 比我用browserify要求它。例如:
  3. var templates = require('templates/all_templates_in_this_js_file_without_extension')();

    3.现在我可以像使用backbonejs模板一样使用它

    Backbone.View.extend({
     template: templates.product, //or templates['product']
     render: function(){
       this.$el.html(this.template(this.model.toJSON()))
     }
    });

相关问题