Search code examples
meteoriron-router

Meteor - Passing helper parameters into pathFor call


I have a helper, "route" that takes in the parameter "foo."

route:function(foo){
  If(foo == x){
      //Stuff
  }
  else{
      //Things
  }
}

This helper returns a dynamic key element of a route I need to create on the front end. I want to format it like these, but neither works.

{{#each arrayOfThings}} <a href="{{pathFor 'path' _id=route "this" }}"></a> {{/each}}

or

{{#each arrayOfThings}} <a href="{{pathFor 'path' _id={{route "this"}} }}"></a> {{/each}}

Solution

  • nested subexpressions can be wrapped in parenthesis to specify the order of evaluation, see Spacebars Readme. I have not tested it but would try:

    {{#each arrayOfThings}} <a href="{{pathFor 'path' _id=(route "this") }}"></a> {{/each}}
    

    Let me know if it works for you.