JRMLSTF
JRMLSTF

Reputation: 85

Yeoman/Grunt does not automatically compile EJS templates with the Backbone generator?

I tried to externalize my Underscore templates in files. Found that using yeoman was a good way to achieve this. I tried to make it works with this code (test.ejs only contains text) :

var test = JST['app/scripts/templates/test.ejs'];
console.log(test());

test() return undefined. I read Template not loading in a Backbone.js app - built using Yeoman and https://github.com/yeoman/generator-backbone/pull/20 especially. But it wasn't help, test() was still undefined.

Finally I read https://github.com/gruntjs/grunt-contrib-jst and tried to run : grun jst which works very well. But I have to run this task each time I edit my templates. I not very used to Grunt but found in Gruntfile.js that it should watch *.ejs files in the templates folder and then run the jst task but it does not work. Any idea ?

Thanks

Upvotes: 0

Views: 1231

Answers (1)

krasu
krasu

Reputation: 2037

You could use https://github.com/gruntjs/grunt-contrib-watch

watch: {
  scripts: {
    files: ['templates/*.ejs'],
    tasks: ['grunt-contrib-jst']
  },
},

Upvotes: 1

Related Questions