Last active
August 29, 2015 14:24
-
-
Save dhollenbeck/98e1ae50efbbac6cea82 to your computer and use it in GitHub Desktop.
Handlebar Template Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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