Ensure "template" is always set when rendering a template

This commit is contained in:
Samy Pesse
2016-04-19 15:46:37 +02:00
parent 61c4983949
commit 53ced205b8
2 changed files with 7 additions and 5 deletions
+2 -4
View File
@@ -154,9 +154,7 @@ WebsiteOutput.prototype.renderAsString = function(tpl, context) {
// Calcul template name
var filename = this.templateName(tpl);
context = _.extend({
template: {}
}, context, {
context = _.extend(context, {
plugins: {
resources: this.resources
},
@@ -167,7 +165,7 @@ WebsiteOutput.prototype.renderAsString = function(tpl, context) {
// Create environment
var env = setupTemplateEnv(this, context);
return Promise.nfcall(env.render.bind(env), filename);
return Promise.nfcall(env.render.bind(env), filename, context);
};
/*
+5 -1
View File
@@ -21,6 +21,11 @@ function templatesPath(dir) {
@return {Nunjucks.Environment}
*/
function setupTemplateEnv(output, context) {
context = _.defaults(context || {}, {
// Required by ThemeLoader
template: {}
});
var loader = new ThemeLoader(
_.map(output.searchPaths, templatesPath)
);
@@ -84,7 +89,6 @@ function setupTemplateEnv(output, context) {
return location.normalize(href);
});
return env;
}