Search code examples
meteoriron-routerspacebars

Pass context variable to linkTo parameter


Let's say I have following Iron.Router's linkTo helper:

{{#each reports}}
  {{#linkTo route='reports' query='q=string' }}Reports{{/linkTo}}
{{/each}}

Is it possible to pass enclosing context variable directly to linkTo without constructing additional helper? Something like this:

{{#each reports}}
  {{#linkTo route='reports' query='q='+_id }}Reports{{/linkTo}}
{{/each}}

I'm aware I can define a helper, e.g. getQuery, that will return 'q'+_id, but is there a way to do this on the fly?


Solution

  • In a word, no. If you look at the Spacebars source, you can see that the function scanArgValue (from line 204 onwards) only accepts a limited number of basic data types, like paths, variables and literals. There's no facility for this sort of (even basic) calculation in Spacebars itself, so you need to be doing it in a helper.