wheelhouse-handlebars

A wheelhouse library to handlebars templates for rendering views

wheelhouse-handlebars

A wheelhouse package for rendering handlebars templates with flatiron.

var flatiron = require('flatiron')
  , app = flatiron.app
  , handlebarsPlugin = require('wheelhouse-handlebars')
 
app.use(flatiron.plugins.http, {})
 
app.use(handlebarsPlugin, {
  templates: '/full/path/to/handlebars/templates' // required. Absolute path. 
  , helpers: '/full/path/to/handlebars/helpers' // optional, if you have handlebars helpers, this is where you load them. Can be an array or a string. 
  , layout: 'layout' // optional, the name of the main layout file. Can be a path relative to your templates directory. 
  , extension: 'hbs' // optional, the extension name for you handlebars templates. Don't prefix with a dot. 
})
 
app.start(8999)

app.render('template/name', data, options)

 
app.router.on('get', 'some/path', function(){
  this.res.end(app.render('home', {hello: 'world'}, {
    title: 'Hello World'
    , meta: {description: 'Sup there Googs?'}
    , myLayoutVar: 'an optional value that defined in your layout template'
  }))
})
 

The main layout files (layout.hbs by default), gets a few variables passed to it which you should include in your layout.

You can look in test/fixtures/templates/layout.hbs for an example of a layout file.

This is the spot in your layout where the templates will be rendered. Same as say… Rails.

Boolean. Are you in an development environment? Useful if you have scripts or somesuch that you only want in your HTML in development.

You can pass this in as an option the the render function to set the title attribute of page.

Also an optional parameter that can be passed into the render method. Should be an object. e.g. {meta: {description: 'A meta description for my page!'}}

  • The main layout for your site should be in a file called layout.hbs

Templates are parsed when you call app.start(), which means that making a change to a template will not be recognized by the server until you restart it.

This is desired behavior in production, but in development it can be a pain, so… there's a way around that!

app.parseTemplates(function(){
  // do something else now that templates have been reparsed. 
})

You must have grunt-cli installed: sudo npm i -g grunt-cli npm test

mocha test/specs -ui bdd