javascript - handlebars layouts and partials in a sails.js application -
i'm developing web application sails.js v0.10 , i'm using handlebars templates, want use layouts , partials. figured out sails.js uses express3-handlebars provide handlebars layouts , partials. can't use both @ same time.
my config/views.js file is:
... engine: 'handlebars', layout: 'layouts/main.handlebars' ...
this works perfectly, layout loaded. problem when i'm try use partials, error saying partial not found.
//usercontroller.js ... index: function(req, res) { res.view({partials: {userlist: 'partials/userlist'}}); ...
this works when change value of config/views.js layout property false. when can't use layouts anymore.
is bug in sails.js? or, doing wrong?
this not bug. design.
in express 3, built-in support layouts/partials deprecated. instead, developers expected rely on view engines implement features. (see https://github.com/balderdashy/sails/issues/494 more info on that.)
since adopting express 3, sails has chosen support legacy layouts feature convenience, backwards compatibility express 2.x , sails 0.8.x apps, , in particular, familiarity new community members coming other mvc frameworks. result, layouts have been tested default view engine (ejs).
if layouts aren’t thing, or (for now) if you’re using server-side view engine other ejs, (e.g. jade, handlebars, haml, dust) you’ll want set layout:false in sails.config.views, rely on view engine’s custom layout/partial support.
Comments
Post a Comment