znat
znat

Reputation: 13474

Meteor - Pass variable in templates arguments

I am trying to do something like this:

<template name=week>
   {{#each days}} //from an array in helpers with values [0,1,2,3,4,5,6]
      {{> day dayOfWeek="<How can I have the value here?>"}}
   {{/each}}
<template name>

Question1: How to retrieve the current value of the array to pass it to the template included?

<template name=day>
   {{#autoForm collection=users doc=user ...}}
      {{#each days}} //from an array in helpers with values [0,1,2,3,4,5,6]
         {{>afFieldInput name='profile.availability.<dayOfWeek>.from'}}
      {{/each}}
   {{/autoForm}}
<template name>

Question 2: How can I dynamically substitute dayOfWeek inside the name?

Upvotes: 2

Views: 1703

Answers (1)

saimeunt
saimeunt

Reputation: 22696

Try this :

Question 1 :

<template name="week">
  {{#each days}} //from an array in helpers with values [0,1,2,3,4,5,6]
    {{> day dayOfWeek=this}}
  {{/each}}
<template name>

Question 2 :

HTML

<template name="day">
  {{#autoForm collection=users doc=user ...}}
    {{#each day in days}} //from an array in helpers with values [0,1,2,3,4,5,6]
      {{> afFieldInput name=name}}
    {{/each}}
  {{/autoForm}}
<template name>

ES2015

Template.day.helpers({
  name(){
    const dayOfWeek = this.dayOfWeek;
    return `profile.availability.${dayOfWeek}.from`;
  }
});

Note : this is using latest Blaze constructs and ES2015 from Meteor 1.2

Upvotes: 3

Related Questions