Access a variable outside the scope of a Handlebars.js each loop

Access a variable outside the scope of a Handlebars.js each loop

I have a handlebars.js template, just like this:
{{externalValue}}

And this is the generated output:
myExternalValue

As expected, I can access the id and title fields of every element of myCollection to generate my select. And outside the select, my externalValue variable is correctly printed (“myExternalValue”).
Unfortunately, in options’ texts, externalValue value is never printed out.
My question is: how can I access a variable outside the scope of the handlebars.js each from within the loop?

Solutions/Answers:

Solution 1:

Try

<option value="{{id}}">{{title}} {{../externalValue}}</option>

The ../ path segment references the parent template scope that should be what you want.

Solution 2:

Or you can use absolute path like this:

<option value="{{id}}">{{title}} {{@root.user.path.to.externalValue}}</option>
Related:  How do I get natural dimensions of an image using javascript or jquery?