Skip to content

Instantly share code, notes, and snippets.

@dhollenbeck
Last active August 29, 2015 14:24
Show Gist options
  • Save dhollenbeck/98e1ae50efbbac6cea82 to your computer and use it in GitHub Desktop.
Save dhollenbeck/98e1ae50efbbac6cea82 to your computer and use it in GitHub Desktop.
Handlebar Template Example
/*
Node.js example of using Handlebars template engine to create custom text strings with custom template functions.
Setup:
- handlebars template language
- swag template helpers
- custom template helpers
*/
var Handlebars = require('handlebars');
var Compile = Handlebars.compile;
var Swag = require('swag');
var helpers = require('path/to/our/helpers');
//register our custom helpers with swag
_.each(helpers, function(fnc, name ){
Swag.addHelper(name, fnc);
});
//register our swag with handlebars
Swag.registerHelpers(Handlebars);
//compile template string (source) to produce a template function
var template = Compile(source);
//merge (user, activity, service) data with template fnc to produce text string
var text = template(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment