<OUTDATED> about {{linkTo}} in Ember.js Guide

15,528

Solution 1

The #linkTo helper takes three parameters.

  1. The route, in your case posts.post
  2. The context, here it is the particular post object you are referring to in the loop
  3. An options hash (currently title is supported)

Because the posts.post route is a dynamic route, e.g. it can be for one of a collection of posts, we must provide the #linkTo helper with which particular post you are wanting to link to.

Solution 2

What the other people said in terms of the arguments passed to the #link-to helper in Ember is accurate here is the link to the documentation for anyone that is looking for more info.

You have the route name that you are linking to and the second argument is providing the model context.

Here is more info:

http://emberjs.com/api/classes/Ember.Templates.helpers.html#method_link-to

Share:
15,528
synthresin
Author by

synthresin

Updated on June 24, 2022

Comments

  • synthresin
    synthresin almost 2 years

    I'm reading guide of Ember.js templates. In the handlebar part of the first example of above link, they used

    {{#linkTo posts.post post}}
    

    but I thought

    {{#linkTo posts.post}}
    

    would work.

    Why do I need second argument 'post'?

    I read the explanation:

    If the route has a dynamic segment, a model that represents the segment. By default, Ember.js will replace the segment with the value of the object's id property.

    but I can't associate this explanation with question above.

  • synthresin
    synthresin over 11 years
    then posts.post in {{#linkTo posts.post post}} isn't related with {{#each post in posts}} but post, posts defined in the router?
  • Bradley Priest
    Bradley Priest over 11 years
    Correct I think you can also use posts/post, but don't quote me on that
  • elrick
    elrick over 8 years
    fixed the link. the location was changed in the new documentation.
  • sova
    sova over 7 years
    "model context" is a good way to say it, as you can wrap multiple dynamic values into one object [and serialize it] so you can have multiple dynamic segments.