Skip to content

Commit

Permalink
Document block parameter implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker committed Aug 1, 2015
1 parent 9b4f9c9 commit 33feeb9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/pages/block_helpers.haml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,30 @@
{{/each}}
{{/each}}

.bullet
.description
A number of <a href="builtin_helpers.html">builtin helpers</a> support block parameters and any custom helper may provide them through the <code>blockParams</code> options field.

:javascript
Handlebars.registerHelper('block-params', function() {
var args = [],
options = arguments[arguments.length - 1];
for (var i = 0; i < arguments.length - 1; i++) {
args.push(arguments[i]);
}

return options.fn(this, {data: options.data, blockParams: args});
});
:html
{{#block-params 1 2 3 as |foo bar baz|}}
{{foo}} {{bar}} {{baz}}
{{/block-params}}

.notes
Implements a helper that allows for named variable declarations within a given block. This example would output <code>1 2 3</code> on render.

.notes
Helpers can determine the number of block paramemters referenced by the template via the <code>options.fn.blockParams</code> field, which is an integer count. This value represents the number of block parameters that could be referenced by the child template. Parameters beyond this cound will never be referenced and can safely be omitted by the helper if desired. This is optional and any additional parameters passed to the template will be silently ignored.

%h2#raw-blocks
Raw Blocks
Expand Down

0 comments on commit 33feeb9

Please sign in to comment.