Meteor – Passing variables to template

In Meteor, a Spacebar template could include another template.

<template name="slots">
  {{> slot }}
</template>

<template name="slot">
  <div class="slot">
    <div class="number">100</div>
  </div>
</template>

 

Sometime we want to reuse the template with different variables. Here is an example.

<template name="slots">
  {{> slot one}}
  {{> slot two}}
  {{> slot three}}
</template>

<template name="slot">
  <div class="slot">
    <div class="number">{{number}}</div>
  </div>
</template>

 

So what is one, two and three stands for? So they are defined in the client side.
client/js/main.js

Template.slots.one = {
  number: 1
}
Template.slots.two = {
  number: 2
}
Template.slots.three = {
  number: 3
}

 

We could even define multiples variables.

Template.slots.one = {
  number: 1,
  another_number: 100,
  ...
}

 

Done =)

Reference: StackOverflow – Is there a way to pass variables into templates in Meteor?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s