Search code examples
javascriptnode.jsmeteorurl-routing

Using current each data inside a query in pathFor iron-router


Just started playing around with meteor and I'm trying to use iron-router for the routing. Here is my data structure:

team
  _id
  name
  tags:[{name,counter}]

And here is the linking I'm trying to use in the template

{{#each team.tags}}
   <a href="{{ pathFor 'team' _id=../team._id query='search='+this.name }}">{{this.name}} <span class="count-list">{{this.counter}}</span></a> 
{{/each}}

And my router has:

route('/team/:_id')  // And I get the search through the GET property... this.params.query 

But it doesn't like query='search='+this.name, how can I make this work?


Solution

  • Because it's a GET method, this should work:

    {{#each team.tags}}
       <a href="{{ pathFor 'team' _id=../team._id}}/?search={{this.name}}">{{this.name}} <span class="count-list">{{this.counter}}</span></a> 
    {{/each}}
    

    Otherwise you would have to build the URL within a helper upfront (or registerHelper function), as spacebars doesn't allow for compound operations.