Skip to content

Instantly share code, notes, and snippets.

@smithcommajoseph
Last active December 20, 2015 19:09
Show Gist options
  • Select an option

  • Save smithcommajoseph/6181253 to your computer and use it in GitHub Desktop.

Select an option

Save smithcommajoseph/6181253 to your computer and use it in GitHub Desktop.
adding Handlebars helpers in a Rendr app
//the client app.js file
var //...
// register your helpers (my method doesn't return anything, so the assignment is unnecessary)
HandlebarsHelpers = require('../assets/handlebars/helpers').registerHelpers();
//...
// ...
rendr_stitch: {
// ...
files: [{
// ...
src: [
// ...
// add your handlebars helpers to the src array to be stitched
'assets/handlebars/*.js'
]
}]
}
}
// a file with some helpers, written in the style of the rendr-handlebars/shared/helpers.js file
var rendrHandlbars = require('rendr-handlebars'),
S = require('string');
function helpers(Handlebars, getTemplate) {
return {
slugify: function(str, block){
return S(str).slugify().s;
}
};
}
exports.registerHelpers = function registerHelpers() {
rendrHandlbars.registerHelpers(helpers);
};
<a href="/{{slugify name}}">
{{name}}
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment