2

Say I have a common piece of markup that will be repeated throughout my website with only a few small differences.

For example, I have a bunch of <div> elements that all have a title.

Elements with class: section-title are all styled the same way, but their text content is different.

I would like to make a template to represent a title, sort of like this:

<template name="section-title">
  <div class="section-title">
    <span> Profile </span>
  </div>
</div>

Except, I need "Profile" to be interchangeable, because I have many different sections: "profile", "contact information", etc.

What is the best way to do this in Blaze?

pneumatics
  • 2,836
  • 1
  • 27
  • 27
Luke
  • 5,567
  • 4
  • 37
  • 66
  • This is a duplicate of http://stackoverflow.com/questions/10128053/is-there-a-way-to-pass-variables-into-templates-in-meteor?rq=1 Sorry about that. – Luke Jul 04 '15 at 18:33

1 Answers1

1

You can use either template arguments or set the template current data context to the appropriate list of arguments.

HTML

<template name="sectionTitle">
  <section class="section-title">
    <span>{{title}}</span>
  </section>
</template>

{{> sectionTitle title="Profile"}}

<template name="parent">
  {{> sectionTitle args}}
</template>

JS

Template.parent.helpers({
  args: function(){
    return {
      title: "Profile"
    };
  }
});
saimeunt
  • 22,666
  • 2
  • 56
  • 61