mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Ensure "template" is always set when rendering a template
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user