我正在使用Foundation for Sites,它使用Panini and Handlebars进行JS模板化。我需要一个包含js变量的{{#ifequal}}
语句,以便我可以将URL参数与JSON进行比较
我现在拥有的:
{{#ifequal "Canada" this.destination}}
//do the thing
{{/ifequal}}
我需要的是这样的事情:
{{#ifequal <script>document.write(destId)</script> this.destination}}
//do the thing
{{/ifequal}}
当js var“destId”被拉出URL参数时,它会在页面的前面分配,但当然我不能在手柄中包含脚本。如果有办法将URL参数直接传递到也可以工作的车把。
答案 0 :(得分:2)
如前所述(link is here):
Handlebars partials采用第二个参数,该参数成为partial的上下文:
{{> person this}}
在版本v2.0.0 alpha及更高版本中,您也可以 传递命名参数的哈希:
{{> person headline='Headline'}}
您可以看到这些测试 场景: 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