Is there a way to pass variables into templates in Meteor?

前端 未结 9 2140
深忆病人
深忆病人 2020-12-01 01:37

I\'ve been experimenting with Meteor and ran into something I couldn\'t figure out. For fun, I was trying to make a slot machine. I had the following HTML:

&         


        
9条回答
  •  囚心锁ツ
    2020-12-01 02:23

    All of the previous answers are overkill or outdated. Here's how you can pass static parameters into templates, directly from HTML+Spacebars code, as of Meteor 0.8.x:

    {{> slot number="1"}} {{> slot number="2"}} ...

    All you have to do is pass key="value" parameters in the {{> template}} inclusion call:

    {{> slot number="1"}}
    

    Learn more at Spacebars Secrets: Exploring Meteor Templates.


    If you want to pass the caller template's data to the child/nested/called template, here's how to do it: pass nothing. Instead, from the nested template, access the parent data context, ../:

    {{> slot number="1"}} {{> slot number="2"}} ...

提交回复
热议问题