You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That will automatically prefix image urls. It works fine, except if I'm using from within a loop, in which case this is the src and not the global options. How can I point this to the global options?
The text was updated successfully, but these errors were encountered:
Unfortunately this is how handlebars handles context. this is always set to the current context which in a block level helper (like a loop) will not be set to the global context. There is current an open issue referencing this: handlebars-lang/handlebars.js#392
One workaround would be to reference the parent context using the ../ syntax. So in your template you might have
Unfortunately you probably can't do this from within a helper. You also need to specify the right number of ../ depending on how deep your context is. So if you are two loops deep you would need ../../ to reach the root context. There may be a more elegant workaround I'm not thinking of.
I'm considering making the renderer used configurable and adding support for https://github.com/linkedin/dustjs because I think that would be more powerful than handlebars. I think adding support to override handlebars from the grunt config with a custom render function first would be best.
How can I retrieve the global options from within helpers.js? Say, for instance, I've got the following:
That will automatically prefix image urls. It works fine, except if I'm using from within a loop, in which case
this
is thesrc
and not the global options. How can I point this to the global options?The text was updated successfully, but these errors were encountered: