【问题标题】:grunt-contrib-handlebars configuration issuegrunt-contrib-handlebars 配置问题
【发布时间】:2023-03-09 22:15:02
【问题描述】:

我对“grunt-contrib-handlebars”的配置有疑问,下面是我目前的设置。

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

这是我目前得到的:

my.namespace["src/templates/baseTemplate.handlebars"]

这就是我想要的:

my.namespace["baseTemplate"]

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

my.namespace.baseTemplate(templateObj);

这个有可能吗?

【问题讨论】:

    标签: javascript gruntjs handlebars.js


    【解决方案1】:

    看看我的解决方案

    我用 browserify 实现了它。

    1. 我生成了一个 .js 文件,其中包含我的所有模板。
    2. 比我对 browserify 的要求要高。示例:

    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()))
     }
    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-08
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 2015-01-25
      • 2013-07-16
      • 1970-01-01
      相关资源
      最近更新 更多