I’m working on a project using Handlebars to render HTML templates.
I’m trying to pass an index from my template to a partial. In my partial, I then attempt to pass it to a custom helper function. The index is correctly displayed in the partial but is undefined within the helper function.
Here’s a simplified version of my setup:
<!-- template code -->
{{#each item}}
{{> feedback index=@index}}
{{/each}}
<feedback>
<!-- The index is shown as expected -->
index?: {{index}}
<h1>
<!-- In the helper, index is undefined -->
{{displayFeedback product='product123' index=index }}
</h1>
</feedback>
Here is the function I am registering:
displayFeedback(options) {
// index is undefined, product is as expected
const { index, product } = options.hash;
// more logic....
};
I have tried directly accessing the context as well as trying to access the parent context with no success.