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
{{ message }}
Repository navigation
Way to access complete data object from helper #320
internal class HandlebarsCultureSpecificTemplateData
{
public Func<string, string> Translate { get; set; }
public CultureInfo Culture { get; set; }
}
Now, this works, until I get into an {{#each}} loop, there data in the helper no longer points to the root object, but points to the current element of the 'each'.
So, my question: how to access the root object from the helper (in all cases) OR how can I execute the helper from the template, but making sure it's getting called from the root scope? (like @root)
In handlebars js, they're passing the options instance to the helper callback, where options.data contains the raw data that is being feeded to the compile function.
@huysentruitw To make sure we've got the use case nailed down, can you please share a simple example template & helper written in handlebars js, with an example JSON model?
Activity
huysentruitw commentedon Oct 23, 2019
Currently changed our usage to:
{{ translate @root "Hello world" }}And helper to:
A cleaner way would be nice :)
rexm commentedon Oct 23, 2019
How does it work in handlebars js?
huysentruitw commentedon Oct 23, 2019
In handlebars js, they're passing the
optionsinstance to the helper callback, whereoptions.datacontains the raw data that is being feeded to the compile function.F.e. https://github.com/wycats/handlebars.js/blob/148b19182d70278237a62d8293db540483a0c46c/lib/handlebars/helpers/with.js
rexm commentedon Oct 29, 2019
@huysentruitw To make sure we've got the use case nailed down, can you please share a simple example template & helper written in handlebars js, with an example JSON model?
Introduce `HelperOptions` Helper and ReturnHelper