Search code examples
javascriptnode.jsmeteorurl-routingiron-router

iron router add parameter to string as well as add a query


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:parent._id query...? }}">#{{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 

So:

  1. How do I get the parent team _id in the template?
  2. How can I pass the _id and the search parameter in the pathFor?

Thanks in advance.


Solution

  • You can make use of ../ to step back to the parent scope, which in this case appears to be teams

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