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/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/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 95fe101..524f9aa 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -145,7 +145,6 @@ Compiler.prototype = { }, PartialStatement: function(partial) { - var partialName = partial.sexpr.path.original; this.usePartial = true; var params = partial.sexpr.params; @@ -155,6 +154,12 @@ Compiler.prototype = { params.push({type: 'PathExpression', parts: [], depth: 0}); } + var partialName = partial.sexpr.name.original, + isDynamic = partial.sexpr.name.type === 'SubExpression'; + if (isDynamic) { + this.accept(partial.sexpr.name); + } + this.setupFullMustacheParams(partial.sexpr, undefined, undefined, true); var indent = partial.indent || ''; @@ -162,7 +167,8 @@ Compiler.prototype = { this.opcode('appendContent', indent); indent = ''; } - this.opcode('invokePartial', partialName, indent); + + this.opcode('invokePartial', isDynamic, partialName, indent); this.opcode('append'); }, |