diff options
author | kpdecker <kpdecker@gmail.com> | 2015-01-18 13:23:45 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-01-18 13:23:45 -0600 |
commit | cb51b82b8e8114aaa3e1b19c41e5c4eebf0539d5 (patch) | |
tree | 386038a4a43f85e19dfee0f996cce66f10c10d8f /lib/handlebars/compiler/javascript-compiler.js | |
parent | b0b522b4f81baf5ba4c190b59abd2b9cfe82bc77 (diff) | |
download | handlebars.js-cb51b82b8e8114aaa3e1b19c41e5c4eebf0539d5.zip handlebars.js-cb51b82b8e8114aaa3e1b19c41e5c4eebf0539d5.tar.gz handlebars.js-cb51b82b8e8114aaa3e1b19c41e5c4eebf0539d5.tar.bz2 |
Add support for dynamic partial names
Uses the subexpression syntax to allow for dynamic partial lookups. Ex:
```
{{> (helper) }}
```
Fixes #933
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 75f9960..a027edb 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -644,17 +644,26 @@ JavaScriptCompiler.prototype = { // // This operation pops off a context, invokes a partial with that context, // and pushes the result of the invocation back. - invokePartial: function(name, indent) { + invokePartial: function(isDynamic, name, indent) { var params = [], options = this.setupParams(name, 1, params, false); + if (isDynamic) { + name = this.popStack(); + delete options.name; + } + if (indent) { options.indent = JSON.stringify(indent); } options.helpers = 'helpers'; options.partials = 'partials'; - params.unshift(this.nameLookup('partials', name, 'partial')); + if (!isDynamic) { + params.unshift(this.nameLookup('partials', name, 'partial')); + } else { + params.unshift(name); + } if (this.options.compat) { options.depths = 'depths'; |