Reputation: 2684
I would like to compile a handlebars template to insert into a static html page. I am currently using a very simple implementation of handlebars where I use AJAX to pull in the data.json and a template in the form of a script tag in my markup: <script id="tpl" type="text/x-handlebars-template">
.
Ideally I would like to use Grunt to compile my template into a new html file, is this possible?
Upvotes: 2
Views: 2458
Reputation: 13273
I would take a look at the assemble grunt plugin. We use for a very large site and it's probably the best handlebars preprocessor I've seen. That said, I'm not sure how it handles (or if it does) the <script type="text/x-handlerbars-template">
tags (versus partials in separate files). We use it with separate files per partial and the task is something like:
assemble: {
options: {
partials: [ "partials/**/*.hbs" ],
data: [ "data/**/*.yml" ]
},
pages: {
src: [ "views/*.hbs" ],
dest: "build/"
}
}
Obviously your setup will be different, but hopefully you get the general idea.
Upvotes: 3
Reputation: 44589
Applying the handlebars template output HTML... Just pass data in, and save the outputted HTML to a file.
I don't know any tools doing this process for you. But it would be very easy to implement.
Upvotes: 1