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

4

7

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.

Circinus answered 22/1, 2013 at 8:0 Comment(1)
sorry, but link is not working :(Slugabed
U
11

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.

Unicellular answered 22/1, 2013 at 8:14 Comment(2)
then posts.post in {{#linkTo posts.post post}} isn't related with {{#each post in posts}} but post, posts defined in the router?Circinus
Correct I think you can also use posts/post, but don't quote me on thatUnicellular
B
4

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

Backwater answered 30/9, 2013 at 21:29 Comment(2)
fixed the link. the location was changed in the new documentation.Backwater
"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.Doer
B
0

For me code below works fine:

  {{#each model as |book|}}
      <h3>{{#link-to 'book' book}}{{book.title}}{{/link-to}}</h3>
  {{/each}}
Backspin answered 19/7, 2015 at 23:30 Comment(0)
B
0

Link-to has format of inline and block

Reference: EmberJS-Template Link To Inline Helper

Baggy answered 16/3, 2017 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.