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

Asked
Active3 hr before
Viewed126 times

7 Answers

variables
90%

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:,1) Passing arguments to the template directly ,lots of good info in here. my specific situation is i also wanted to pass in some template data.,All you have to do is pass key="value" parameters in the {{> template}} inclusion call:

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:

<div class="slot-wrapper">
  {{> slot number="1"}}
  {{> slot number="2"}}
  ...
</div>

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

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

{
   {
      > slot number = "1"
   }
}

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, ../:

<div class="slot-wrapper">
  {{> slot number="1"}}
  {{> slot number="2"}}
  ...
</div>

<template name="slot">
  <div>Machine name: {{../name}}</div>
  <div class="number"><span>{{number}}</span></div>
</template>
load more v
88%

Is there a way to pass variables from an #each loop into the helper?,I’m trying to use a template helper that requires two parameters. It works when I hard code values in this this:,But what I’d like to do is use variables from the #each loop like so:,Just omit the curly brackets on amount & spent

I’m trying to use a template helper that requires two parameters. It works when I hard code values in this this:

{
   {
      remaining "100.00"
      "55.00"
   }
}
load more v
72%

How to use the Spacebars language to define templates rendered by the Blaze engine.,It’s more flexible, in case you need to give the component more arguments in the future.,This means when you render a Blaze template, you are simply running a function on the client that corresponds to the Spacebars content you defined in the .html file.,How the Blaze rendering engine works under the hood and some advanced techniques for using it.

As an example, consider the Todos_item template from the Todos example app:

<template name="Todos_item">
  <div class="list-item {{checkedClass todo}} {{editingClass editing}}">
    <label class="checkbox">
      <input type="checkbox" checked={{todo.checked}} name="checked">
      <span class="checkbox-custom"></span>
    </label>

    <input type="text" value="{{todo.text}}" placeholder="Task name">
    <a class="js-delete-item delete-item" href="#">
      <span class="icon-trash"></span>
    </a>
  </div>
</template>
load more v
65%

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:,1) Passing arguments to the template directly ,As you see we can specify the template instances in any order. The second parameter is actually a variable that should be defined, so:,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, ../:

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:

<div class="slot-wrapper">
  {{> slot}}
  {{> slot}}
  {{> slot}}
</div>

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

I want to have a different number for each slot. Is it possible to pass variables into template? Something like this:

<div class="slot-wrapper">
  {{> slot 1}}
  {{> slot 2}}
  {{> slot 3}}
</div>

<template name="slot">
  <div class="slot">
    <div class="number"><span>{{ number i}}</span></div>
    <div class="divider"></div>
  </div>
</template>
load more v
75%

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:,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, ../:,Learn more at Spacebars Secrets: Exploring Meteor Templates.,All you have to do is pass key="value" parameters in the {{> template}} inclusion call:

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:

<div class="slot-wrapper">
  {{> slot}}
  {{> slot}}
  {{> slot}}
</div>

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

I want to have a different number for each slot. Is it possible to pass variables into template? Something like this:

<div class="slot-wrapper">
  {{> slot 1}}
  {{> slot 2}}
  {{> slot 3}}
</div>

<template name="slot">
  <div class="slot">
    <div class="number"><span>{{ number i}}</span></div>
    <div class="divider"></div>
  </div>
</template>
load more v
40%

Successfully merging a pull request may close this issue.,Spacebars nested expressions made it into Meteor 1.2, so closing this issue. Thanks!,Do spacebars nested expressions help? (#4101),Spacebars nested expressions is exactly the solution! Looks like it's also now part of the devel branch, but I can't tell if that's merged with the current release 1.1.0.2 (it throws a Type Error).

// a global helper that composites the template's name using domain-specific and global parameters
Template.registerHelper('templateName', function(name) {
   return name + Session.get('someVariable');
});
load more v
22%

Sometimes we have requirement for using result of one template into other template in Meteor and this is very common thing to use.,http://stackoverflow.com/questions/37937964/how-to-send-some-data-of-one-template-to-another-template-meteor,So in this blog I am going to explain how you can use one template data in other template.,So in this way you can share data between multiple templates.

Template.allInventory.rendered = function() {
      Template.allInventory.events({
         "click .btn": function(e) {
            data = $(e.target).attr('data');
            Router.go('productDetail', {
               data: $(e.target).attr('data')
            }, {
               query: 'q=s',
               hash: 'hashFrag'
            });
            console.log(data);
         }
      })
load more v

Other "variables-undefined" queries related to "Is there a way to pass variables into templates in Meteor?"