0

I've the following code:

<ul>
{{#each title}}
    <li><a href="{{pathFor 'tplTitle'}}">{{this}}</a></li>
{{/each}}
</ul>

"title" is an array of strings: ["A title","Another title","End title"]

The router's code:

this.route("tplTitle", {
    path:"/title/:sometitle",
    data: function(){
       return [... a search using "sometitle" argument ...]
    })

The problem: {{pathFor 'tplTitle'}} returns an empty string, even if I put in the path: "/title/:this" (it weird, but maybe works :P).

In the docs, I cannot found information about this problem with pathFor :(

How can I do this?

- EDIT -

I found this solution:

<li><a href="{{pathFor 'article' _id=this._id }}">{{title}}</a></li>

source: How to pass a parameter to pathFor in Handlebars for Iron-Router with Meteorite?

And it works! But its this solution elegant?

Community
  • 1
  • 1
Imaky
  • 1,227
  • 1
  • 16
  • 36

1 Answers1

1

Looks good to me. Per https://github.com/EventedMind/iron-router/blob/master/lib/client/ui/helpers.js#L42:

/**
 * Example Use:
 *
 *  {{pathFor 'items' params=this}}
 *  {{pathFor 'items' id=5 query="view=all" hash="somehash"}}
 *  {{pathFor route='items' id=5 query="view=all" hash="somehash"}}
 */
m2web
  • 737
  • 6
  • 15