Ghost/core/server/helpers/template.js
Hannah Wolfe 3961b7173f Upgrade express-hbs, and switch to using registerPartial
fixes #1964, fixes #1975

 - Issues with partial handling which caused #1964  have been part fixed by handlebars, part worked around by express-hbs, we must use `registerPartials` to ensure partials are handled correctly.
 - Issue with error handling which caused #1975 has also been fixed in express-hbs, which now catches the error from handlebars and passes it to express so that we can handle the error with an error page.
2014-01-24 11:08:15 +00:00

26 lines
701 B
JavaScript

var templates = {},
hbs = require('express-hbs'),
errors = require('../errorHandling');
// ## Template utils
// Execute a template helper
// All template helpers are register as partial view.
templates.execute = function (name, context) {
var partial = hbs.handlebars.partials[name];
if (partial === undefined) {
errors.logAndThrowError('Template ' + name + ' not found.');
return;
}
// If the partial view is not compiled, it compiles and saves in handlebars
if (typeof partial === 'string') {
hbs.registerPartial(partial);
}
return new hbs.handlebars.SafeString(partial(context));
};
module.exports = templates;