Book Image

Meteor Cookbook

By : Isaac Strack
Book Image

Meteor Cookbook

By: Isaac Strack

Overview of this book

Table of Contents (19 chapters)
Meteor Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using dynamic templates


Meteor has yet another templating trick up its sleeve! In addition to custom code blocks, reactive data contexts, and all the other various template niceties, Meteor also allows you to dynamically switch between rendered templates. This recipe will show you how to dynamically render templates, using the Template.dynamic helper.

Getting ready

We will use the codebase from the Creating custom components recipe found in this chapter. Please follow that recipe first or download the corresponding codebase.

How to do it...

We will add a dynamic template that will switch our shapes from circles to squares, when rendered. Proceed with the following steps to use dynamic templates:

  1. First, we need to create our alternate template. Inside templates.html, located in your [project root]/client folder, add the following template, just below the declaration for the existing one template:

    <template name="two">
        {{#each svgShapes}}
            <rect x="{{x}}" y="{{y}}" width="80...