Jérémie Parker Jérémie Parker - 1 year ago 161
Javascript Question

How to configure partials and layouts for Handlebars in Sails.js?

I run Sails

and have installed Handlebars which is supported by Consolidate.js and therefore is supported by Sails

I can serve pages from
files, it works just fine.
I can't figure where, in Sails workflow, and in a Sails way, I should register partials, helpers etc... I'm more looking for best practices than just a working solution but any help will be appreciated.

Answer Source

I'm running v0.10 beta but this shouldn't affect how I got it working below:

  1. Engine should be handlebars as expected
  2. Routes need to explicitly define controller and action. Setting view won't work. (Unless there's a way I couldn't figure out of setting the partials in the routes file)
  3. Controller needs partials defined as paths relative to the view.


module.exports.views = {
  engine      : 'handlebars',
  layout      : false


'/': {
  controller: 'site',
  action: 'index'


module.exports = {
  // Render Index View
  index: function(req, res) {
      partials: {
        head: 'partials/head',
        tail: '../partials/tail',


{{> head}}
<h3>SITE INDEX</h3>


{{> tail}}


<h2>HEAD TAIL</h2>


<h2>HEAD TAIL</h2>
<h3>SITE INDEX</h3>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download