grunt-contrib-handlebars配置问题 [英] grunt-contrib-handlebars configuration issue

查看:158
本文介绍了grunt-contrib-handlebars配置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在配置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); 

是否可以得到这个?

解决方案

看看我的解决方案



我用browserify实现了它。


  1. 我生成了一个包含我所有模板的.js文件。

  2. browserify。示例:

var templates = require( ')();();



我可以像backbonejs模板一样使用它

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


I have an issue with the configuration of "grunt-contrib-handlebars", below is my setup at the moment.

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

This is what I get at the moment:

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

This is what I want:

my.namespace["baseTemplate"]

So I can call the templates like this:

my.namespace.baseTemplate(templateObj);

Is it possible to get this?

解决方案

Take a look my solution

I implemented it with browserify.

  1. I generated a .js file that contains all my templates.
  2. Than I required it with browserify. Example:

var templates = require('templates/all_templates_in_this_js_file_without_extension')();

3.And now I can use it like backbonejs template

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

这篇关于grunt-contrib-handlebars配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆