From f4d5996a8823a1ba51dd5d84f4b7347eb4bb062e Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Wed, 18 Oct 2017 13:49:03 +0200 Subject: [PATCH] Allow use of .njk extension for template files. --- js/module.js | 7 +++++-- modules/default/helloworld/helloworld.js | 2 +- .../default/helloworld/{helloworld.html => helloworld.njk} | 0 3 files changed, 6 insertions(+), 3 deletions(-) rename modules/default/helloworld/{helloworld.html => helloworld.njk} (100%) diff --git a/js/module.js b/js/module.js index 43a1603a..464509ee 100644 --- a/js/module.js +++ b/js/module.js @@ -86,7 +86,7 @@ var Module = Class.extend({ var templateData = this.getTemplateData(); // Check to see if we need to render a template string or a file. - if (/^.*(\.html)$/.test(template)) { + if (/^.*((\.html)|(\.njk))$/.test(template)) { // the template is a filename this.nunjucksEnvironment().render(template, templateData, function (err, res) { if (err) { @@ -170,7 +170,10 @@ var Module = Class.extend({ var self = this; - this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), {async: true})); + this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), {async: true}), { + trimBlocks: true, + lstripBlocks: true + }); this._nunjucksEnvironment.addFilter("translate", function(str) { return self.translate(str) }); diff --git a/modules/default/helloworld/helloworld.js b/modules/default/helloworld/helloworld.js index 4de10acd..a1fb9d7d 100644 --- a/modules/default/helloworld/helloworld.js +++ b/modules/default/helloworld/helloworld.js @@ -15,7 +15,7 @@ Module.register("helloworld",{ }, getTemplate: function () { - return "helloworld.html" + return "helloworld.njk" }, getTemplateData: function () { diff --git a/modules/default/helloworld/helloworld.html b/modules/default/helloworld/helloworld.njk similarity index 100% rename from modules/default/helloworld/helloworld.html rename to modules/default/helloworld/helloworld.njk