wheelhouse-handlebars
A wheelhouse package for rendering handlebars templates with flatiron.
Usage
Setup
var flatiron = app = flatironapp handlebarsPlugin = app app appstart8999
rendering
app.render('template/name', data, options)
approuter
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
Creating a new helper
var Handlebars = // define your helper function { return 'hello! ' + contextmsg} // export a function that accepts a handlebars instancemodule{ // if we haven't been given a handlebars instance, use the one we required. This will work fine browser-side, but not in node, you must pass the handlebars instance you want to attach to (this plugin does that for you.) handlebars || handlebars = Handlebars return handlebars}
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
Changelog
0.3.5
- typo in last release notes
0.3.4
- If the requested template isn't cached, throw an error
- Updated lodash and misc dev dependencies
0.3.2
- Breaking change: helpers must now return a function that accepts a single argument: the
Handlebars
instances you want to attach the helper to. If you don't pass a handlebars instance, it will require handlebars and use that instance (works great client side)