0

I'm using Foundation for Sites which uses Panini and Handlebars for JS templating. I need an {{#ifequal}} statement that includes a js variable so that I can compare a URL parameter to a JSON

What I have right now:

{{#ifequal "Canada" this.destination}} //do the thing {{/ifequal}}

What I need is something like this:

{{#ifequal <script>document.write(destId)</script> this.destination}} //do the thing {{/ifequal}}

The js var "destId" is assigned earlier in the page when it's pulled out of the URL parameters, but of course I can't include the script inside the handlebars. If there's a way to pass a URL parameter directly into a handlebar that would also work.

1 Answers1

1

as noted before on this question (link is here):

Handlebars partials take a second parameter which becomes the context for the partial:

{{> person this}}

In versions v2.0.0 alpha and later, you can also pass a hash of named parameters:

{{> person headline='Headline'}}

You can see the tests for these scenarios: https://github.com/wycats/handlebars.js/blob/ce74c36118ffed1779889d97e6a2a1028ae61510/spec/qunit_spec.js#L456-L462 https://github.com/wycats/handlebars.js/blob/e290ec24f131f89ddf2c6aeb707a4884d41c3c6d/spec/partials.js#L26-L32

Community
  • 1
  • 1
elicohenator
  • 747
  • 6
  • 17