diff --git a/lib/hooks/views/layoutshim.js b/lib/hooks/views/layoutshim.js index d8aa5ae3b..79753c88d 100644 --- a/lib/hooks/views/layoutshim.js +++ b/lib/hooks/views/layoutshim.js @@ -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; } } }