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

synthresin picture synthresin · Jan 22, 2013 · Viewed 15.5k times · Source

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.

Answer

Bradley Priest picture Bradley Priest · Jan 22, 2013

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.