Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using {{#link-to}} within {{#each}} with a parent template variable in Ember.js

I'm trying to generalize a component which occurs a number of times throughout our UI.

There is a variable item-type which is passed into the component and currently I'm trying to use it like so:

{{#each items}}
    {{#link-to ../item-type this ...}}...{{/link-to}}
{{/each}}

I get this error:

This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.

However, logging the variable works fine:

{{#each items}}
    {{log ../item-type}}
{{/each}}

Of course, if I exchange ../item-type with its value (hardcoded) it works fine.

Does link-to not support this handlebars macro?

If not, is there an alternative binding that can be done with a handlebar helper?

like image 211
Ian Bishop Avatar asked Mar 22 '23 07:03

Ian Bishop


1 Answers

I ended up solving it by binding the parent context using a {{#with}}.

I can't imagine this is the suggested method, so I'll leave the question open if anyone who knows the real answer comes around.

Example:

{{#with this as component}}
    {{#each items}}
        {{#link-to component.item-type this ..}}...{{/link-to}}
    {{/each}}
{{/with}}

Edit: It's been nearly 2 years and this is still listed in the Ember team's spreadsheet of unresolved SO bugs. I'm going to close it now.

like image 109
Ian Bishop Avatar answered Apr 28 '23 15:04

Ian Bishop