Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

wheelhouse-handlebars

joeybaker8BSD0.3.7

A wheelhouse library to handlebars templates for rendering views

flatiron, templates, connect, views, handlebars, wheelhouse

readme

wheelhouse-handlebars

A wheelhouse package for rendering handlebars templates with flatiron.

Usage

Setup

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)

rendering

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'
  }))
})

Layout config options

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.

{{yield}}

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

{{_development}}

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

{{title}}

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

{{meta}}

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

template parsing

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.
})

tests

The grunt way

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

The Mocha way

mocha test/specs -ui bdd