diff --git a/README.md b/README.md index ee32108ae..5c6476574 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ Defaults to `["."]` * `cache` indicates whether or not to cache resolved templates. Defaults to `false`. +* `dynamicPartials`: if set, treat `` parameter in `{%include filepath %}`, `{%layout filepath%}` as a variable, otherwise as a literal value. Defaults to `true`. + * `strict_filters` is used to enable strict filter existence. If set to `false`, undefined filters will be rendered as empty string. Otherwise, undefined filters will cause an exception. Defaults to `false`. * `strict_variables` is used to enable strict variable derivation. diff --git a/index.js b/index.js index e73532192..0d9b50ff1 100644 --- a/index.js +++ b/index.js @@ -115,6 +115,7 @@ function factory (options) { root: ['.'], cache: false, extname: '', + dynamicPartials: true, trim_tag_right: false, trim_tag_left: false, trim_value_right: false, diff --git a/src/scope.js b/src/scope.js index f5033c2aa..6a88279f8 100644 --- a/src/scope.js +++ b/src/scope.js @@ -172,6 +172,7 @@ function matchRightBracket (str, begin) { exports.factory = function (ctx, opts) { var defaultOptions = { + dynamicPartials: true, strict_variables: false, strict_filters: false, blocks: {}, diff --git a/tags/include.js b/tags/include.js index 91f231271..5f944b4d9 100644 --- a/tags/include.js +++ b/tags/include.js @@ -16,7 +16,10 @@ module.exports = function (liquid) { } }, render: function (scope, hash) { - var filepath = Liquid.evalValue(this.value, scope) + var filepath = this.value + if (scope.opts.dynamicPartials) { + filepath = Liquid.evalValue(this.value, scope) + } var originBlocks = scope.opts.blocks var originBlockMode = scope.opts.blockMode diff --git a/tags/layout.js b/tags/layout.js index fc7af5443..21c8efc0b 100644 --- a/tags/layout.js +++ b/tags/layout.js @@ -19,7 +19,7 @@ module.exports = function (liquid) { this.tpls = liquid.parser.parse(remainTokens) }, render: function (scope, hash) { - var layout = Liquid.evalValue(this.layout, scope) + var layout = scope.opts.dynamicPartials ? Liquid.evalValue(this.layout, scope) : this.layout // render the remaining tokens immediately scope.opts.blockMode = 'store' diff --git a/test/tags/include.js b/test/tags/include.js index fcd8cb23b..a7a2206e3 100644 --- a/test/tags/include.js +++ b/test/tags/include.js @@ -88,4 +88,14 @@ describe('tags/include', function () { return expect(liquid.renderFile('personInfo.html', ctx)).to .eventually.equal('This is a person

Joe Shmoe
City: Dallas

') }) + + it('should support static filename', function () { + var staticLiquid = new Liquid({dynamicPartials: false, root: '/'}) + mock({ + '/with.html': 'X{% include color.html shape: "rect" %}Y', + '/color.html': 'shape:{{shape}}' + }) + return expect(staticLiquid.renderFile('with.html')).to + .eventually.equal('Xshape:rectY') + }) }) diff --git a/test/tags/layout.js b/test/tags/layout.js index c5444826a..290a2a88f 100644 --- a/test/tags/layout.js +++ b/test/tags/layout.js @@ -96,4 +96,13 @@ describe('tags/layout', function () { return expect(liquid.renderFile('/main.html')).to .eventually.equal('blackredA') }) + it('should support static filename', function () { + mock({ + '/parent.html': '{{color}}{%block%}{%endblock%}', + '/main.html': '{% layout parent.html color:"black"%}{%block%}A{%endblock%}' + }) + var staticLiquid = Liquid({ root: '/', dynamicPartials: false }) + return expect(staticLiquid.renderFile('/main.html')).to + .eventually.equal('blackA') + }) })