Ian Bishop
Ian Bishop

Reputation: 5205

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?

Upvotes: 4

Views: 1473

Answers (1)

Ian Bishop
Ian Bishop

Reputation: 5205

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.

Upvotes: 7

Related Questions