Skip to content

Commit

Permalink
Fix layouts for now by not waiting for the http hook to load.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgress454 committed Sep 2, 2015
1 parent 5c3a23c commit 5395854
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions lib/hooks/views/layoutshim.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,23 @@ module.exports = function layoutshim (sails) {

// Use ejs-locals for all ejs templates
if (engineName === 'ejs') {

var ejsLayoutEngine = require('ejs-locals');

// Wait until express is ready, then configure the view engine
return sails.after('hook:http:loaded', function () {
sails.log.verbose('Overriding ejs engine config with ejslocals to implement layout support...');
sails.config.views.engine.fn = ejsLayoutEngine;
});
sails.log.verbose('Overriding ejs engine config with ejslocals to implement layout support...');
sails.config.views.engine.fn = ejsLayoutEngine;
}

// Use express-handlebars for handlebars templates, and set up layout functionality
else if (engineName === 'handlebars') {
var exphbs = require('express-handlebars');
return sails.after('hook:http:loaded', function() {
sails.log.verbose('Overriding handlebars engine with express-handlebars to implement layout support...');
var hbs = exphbs.create({
defaultLayout: path.join('..', (sails.config.views.layout + '.' + (sails.config.views.extension || 'handlebars')) || ''),
helpers: sails.config.views.helpers || {},
partialsDir: path.join('views', sails.config.views.partials || ''),
extname: sails.config.views.extension
});

sails.config.views.engine.fn = hbs.engine;
sails.log.verbose('Overriding handlebars engine with express-handlebars to implement layout support...');
var hbs = exphbs.create({
defaultLayout: path.join('..', (sails.config.views.layout + '.' + (sails.config.views.extension || 'handlebars')) || ''),
helpers: sails.config.views.helpers || {},
partialsDir: path.join('views', sails.config.views.partials || ''),
extname: sails.config.views.extension
});

sails.config.views.engine.fn = hbs.engine;
}
}
}
Expand Down

0 comments on commit 5395854

Please sign in to comment.