Skip to content

Commit 7fb9750

Browse files
committed
Update block helper docs in README
Fixes handlebars-lang#231, handlebars-lang#259
1 parent c95d9d6 commit 7fb9750

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

README.markdown

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ template(context);
7272
// </ul>
7373
```
7474

75+
Helpers take precedence over fields defined on the context. To access a field
76+
that is masked by a helper, a path reference may be used. In the example above
77+
a field named `link_to` on the `context` object would be referenced using:
78+
79+
```
80+
{{./link_to}}
81+
```
82+
7583
Escaping
7684
--------
7785

@@ -130,7 +138,7 @@ When calling a helper, you can pass paths or Strings as parameters. For
130138
instance:
131139

132140
```js
133-
Handlebars.registerHelper('link_to', function(title) {
141+
Handlebars.registerHelper('link_to', function(title, options) {
134142
return "<a href='/posts" + this.url + "'>" + title + "!</a>"
135143
});
136144

@@ -177,12 +185,18 @@ template(data);
177185
// </ul>
178186
```
179187

180-
Whenever the block helper is called it is given two parameters, the
181-
argument that is passed to the helper, or the current context if no
182-
argument is passed and the compiled contents of the block. Inside of
183-
the block helper the value of `this` is the current context, wrapped to
184-
include a method named `__get__` that helps translate paths into values
185-
within the helpers.
188+
Whenever the block helper is called it is given one or more parameters,
189+
any arguments that are passed in the helper in the call and an `options`
190+
object containing the `fn` function which executes the block's child.
191+
The block's current context may be accessed through `this`.
192+
193+
Block helpers have the same syntax as mustache sections but should not be
194+
confused with one another. Sections are akin to an implicit `each` or
195+
`with` statement depending on the input data and helpers are explicit
196+
pieces of code that are free to implement whatever behavior they like.
197+
The [mustache spec](http://mustache.github.io/mustache.5.html)
198+
defines the exact behavior of sections. In the case of name conflicts,
199+
helpers are given priority.
186200

187201
### Partials
188202

0 commit comments

Comments
 (0)