Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think figured your problem.</p> <p><strong>1. You got your example mixed up</strong></p> <p>You are adding <code>'root'</code> to the <code>my-link-to-works</code> helper:</p> <pre><code>{{#my-link-to-works 'root' widget.href}} </code></pre> <p>and doing the unshift on the <code>my-link-to-fails</code> helper. So actually both examples are different. One has two arguments (ex: 'root' and '/widget/foo') and the other only has one (ex: '/widget/foo').</p> <p><strong>2. Anyway, why does it work when the first argument is 'root'?</strong></p> <p>The <a href="http://emberjs.com/api/classes/Ember.Handlebars.helpers.html#method_link-to" rel="nofollow">link-to helper</a> first argument must be a <code>routeName</code>. This helper can also receive a second argument <a href="http://emberjs.com/api/classes/Ember.Handlebars.helpers.html#toc_supplying-an-explicit-dynamic-segment-value" rel="nofollow">supplying an explicit dynamic segment value</a> which appends it's value to the resolved route. This was how your arguments were interpreted. If you check your example, the working links resolve to, for example, <code>#//widget/foo</code>. You may notice the two forward slashes there, which are a result of your resolved route <code>#/</code> + your segment value <code>/widget/foo</code>.</p> <p><strong>3. Solution?</strong></p> <p>Use the link-to helper directly: <code>{{link-to 'widget' 'widget.href'}}</code> and remove the <code>/widget/</code> part from your href strings or do something like this: <a href="http://jsfiddle.net/tqFJ3/4/" rel="nofollow">http://jsfiddle.net/tqFJ3/4/</a></p> <p>The helper: (this is the same as using <code>link-to</code> directly)</p> <pre><code>Ember.Handlebars.registerHelper('my-link-to-works', function() { // Do extra stuff here... return Ember.Handlebars.helpers['link-to'].apply(this, arguments); }); </code></pre> <p>Change your widgets href and leave only the dynamic segments:</p> <pre><code>App.IndexRoute = Ember.Route.extend({ model : function() { return { widgets: [ { href: 'foo' }, { href: 'bar' }, { href: 'baz' } ] }; } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload