Search code examples
handlebars.jsmustache

How to get originating context of helper in handlebars?


I am creating a custom helper.

If I use my new helper within an object like this:

{{#data}}
    {{newHelper}}
{{/data}}

How do I access the data object from my helper function?

I know I can do

args.data.root['data']

But I want to access it dynamically because it wont always be within an object called 'data', it could be anything.


Solution

  • You can access the current context with this

    So instead of using args.data.root['data'].value you can simply use this.value