I run Sails 0.9.7
and have installed Handlebars which is supported by Consolidate.js and therefore is supported by Sails
I can serve pages from .handlebars
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.
I'm running v0.10 beta but this shouldn't affect how I got it working below:
config/views.js
module.exports.views = {
engine : 'handlebars',
layout : false
};
config/routes.js
'/': {
controller: 'site',
action: 'index'
},
SiteController.js
module.exports = {
// Render Index View
index: function(req, res) {
res.view({
partials: {
head: 'partials/head',
tail: '../partials/tail',
},
});
}
};
views/site/index.handlebars
{{> head}}
<h3>SITE INDEX</h3>
views/site/partials/head.handlebars
<h1>HEAD</h1>
{{> tail}}
views/partials/tail.handlebars
<h2>HEAD TAIL</h2>
<h1>HEAD</h1>
<h2>HEAD TAIL</h2>
<h3>SITE INDEX</h3>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With