0.0.2 • Published 10 years ago

folio-handlebars v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

FolioHandlebars

Folio.js handlebars render engine

Build Status Dependency Status devDependency Status Code Climate

Install

The best way to add Folio-Handlebars to your folio.js project is to use npm.

npm install folio-handlebars --save

Example Usage

// Require folio.js
var Folio = require('folio.js');
var FolioHandlebars = require('folio-handlebars');

// Create a new folio.js application
var myApp = new Folio();

// Create Folio-Handlebars instance
var folioHandlebars = new FolioHandlebars();

// Set as render engine
myApp.setRenderEngine(folioHandlebars);

// Register templates
folioHandlebars.registerTemplate('HelloWorld', __dirname + '/templates/helloWorld.html');

// Register Partials
folioHandlebars.registerPartial('MyPartial', __dirname + '/templates/partials/MyPartial.html');

// Set up route
myApp.get('/hello-world').handler(function(request, response) {

    var myModel = {
    	type: 'cupboard'
    };

    // Render the 'HelloWorld' view with a given model
    response.render('HelloWorld', myModel);
});

// Start the server, and have it listen for requests on port 3000.
myapp.start(3000);

API

registerTemplate(viewName, path, options)

NameTypeAttribuesDescription
viewNameStringThe name of the view that will be referenced when rendering
pathStringThe absolute path to the template on disk
optionsObjectOptionalOptions that should be passed to handlebars when compiling the template

Registers a template with handlebars.

registerPartial(name, path)

NameTypeDescription
nameStringThe name of the partial as used by referencing templates
pathStringThe absolute path to the partial on disk

Registers a partial with handlebars.

render(viewName, model) -> {String}

NameTypeDescription
viewNameStringThe view's name to render as registered previously
modelObjectThe model to be passed to the template when rendering

Render a view with a model. This method should not be called directly, but via the response object. See above example.

License

FolioHandlebars is licensed under the MIT license.