Skip to content

raptorjs/view-engine-handlebars

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

view-engine-handlebars

Handlebars view engine

Installation

npm install view-engine-handlebars --save

Usage

Enable the Handlebars view engine:

require('view-engine').configure({
    engines: {
        'view-engine-handlebars': {
            extensions: ['hbs']
        }
    }
})

The Handlebars view engine is now ready to be used elsewhere in your code (either client-side or server-side):

var templatePath = require.resolve('./hello.hbs');
var template = require('view-engine').load(templatePath);

// Callback-style
template.render({ name: 'John'}, function(err, data) {
    if (err) {
        console.log('Failed to render: ' + err);
        return;
    }

    console.log('Output: ' + data);
});

// Streaming-style
var out = require('fs').createOutputStream('hello.out', {encoding: 'utf8'});
template.stream({ name: 'John'}).pipe(out);

// Render to an existing render context
template.render({ name: 'John'}, context);

See the documentation for the view-engine module for more information.