Skip to content

Instantly share code, notes, and snippets.

@tracend
Last active December 15, 2015 21:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tracend/5330007 to your computer and use it in GitHub Desktop.
Handlebars Grunt: Using grunt-render in handlebars templates https://github.com/makesites/grunt-render/
hbs.registerHelper('grunt', function(type, name) {
var options = {};
// fallbacks...
// if there is no type, exit now
if(typeof type == "undefined") return;
options.type = type;
// fallback for name
if(typeof name == "string"){
options.name = name;
}
// fn will compile the body section between the tags
var files = arguments[arguments.length-1].fn || false;
if( files ){
options.files = files();
};
// remove last (internal) argument
//var options = arguments;
//delete options[arguments.length-1];
var grunt = require('grunt-render')( options );
var html = grunt[type]( options );
return new hbs.SafeString( html );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment