Ghost/core/server/helpers/template.js
Seb Gotvitch fef9b4be25 Bug fixes for partial views
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
2013-12-12 12:11:02 -05:00

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;