New Helper: Each Include Parent - (Works with partials)#385
New Helper: Each Include Parent - (Works with partials)#385AndrewHenderson wants to merge 1 commit intohandlebars-lang:masterfrom AndrewHenderson:master
Conversation
This helper allows a parent context to be accessed when using partial templates.
Note: It has no dependencies other than Handlebars. Uses a local _each function that is a port of jQuey.each.
Usage: {{#eachIncludeParent context parent=this}}{{> template-partial }}{{/eachIncludeParent}}
See demo: jsFiddle - http://jsfiddle.net/AndrewHenderson/kQZpu/4/
Comment Thread: #182 (comment)
|
I think this might be a better approach: #368 |
|
I like this approach, however it fails the build test. I tried to get to work on JsFiddle (http://jsfiddle.net/kQZpu/11/), but I get an error. There seems to be an issue with the return statement: That line throws the following error, which you can see in console: I tried investigating those Handlebars methods, but they're not documented and are difficult to trace. |
|
One issue may be that you're using an older version of Handlebars (1.0.0beta6). Use this version, which is one of the last releases (post-1.0.0.rc1): https://dl.dropbox.com/u/22528488/handlebars.js |
|
Thanks. I updated the version. No longer receive the error, however the context is lost an variables are returned undefined. http://jsfiddle.net/AndrewHenderson/kQZpu/13/. Look in console for logging. Have you been able to get this to work in a reduced test case? |
|
It looks like you must merge the template name into the hash. If you keep them separate, it goofs the options hash |
|
FWIW, I prefer to just have the partial called like so... See http://jsfiddle.net/QV9em/4/ for a working sample |
|
I'm sorry for not giving this any attention after being opened so long ago. The hash passing approach is a good one but this should be part of the core partials syntax as it avoids the caveat above and make this a proper first level implementation. I will provide an update on #182 implementing something to that effect. |
This helper allows a parent context to be accessed when using partial templates inside of an each.
Note: It has no dependencies other than Handlebars. Uses a local _each function that is a port of jQuey.each.
Usage: {{#eachIncludeParent context parent=this}}{{> template-partial }}{{/eachIncludeParent}}
See demo: jsFiddle - http://jsfiddle.net/AndrewHenderson/kQZpu/5/
Comment Thread: #182 (comment)