mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
fef9b4be25
closes #1203 - Update express-hbs module to the new version (0.5.2) - Use two instance of hbs one for the theme and an other for the admin - Template helpers are register as partial view - Partial views of the theme are reload when the theme changed Remove clear partial cache in handlebars This code will be move in `express-hbs`. This doesn't cause a problem to remove this line but it is not clean. Remove unused hbs instance Resolve conflict
27 lines
763 B
JavaScript
27 lines
763 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') {
|
|
partial = hbs.handlebars.compile(partial);
|
|
hbs.handlebars.partials[name] = partial;
|
|
}
|
|
|
|
return new hbs.handlebars.SafeString(partial(context));
|
|
};
|
|
|
|
module.exports = templates; |