mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
3961b7173f
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.
26 lines
701 B
JavaScript
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; |