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

Creating customized global helpers


As you begin to really dig into templates, you'll soon discover how truly great template helpers are. You can access data inline and drastically reduce the amount of code you need to write.

You will, however, eventually run into a situation where you find yourself repeating the same logic in multiple, in-template helpers. Wouldn't it be great if there was a way to create global helpers accessible from any template? Well, Meteor has a solution for this too! This recipe will show you how to create global template helpers using the Template.registerHelper function.

Getting ready

We will use the codebase from the Building a smooth interface with Bootstrap recipe, found in this chapter. Please follow that recipe first or download the corresponding codebase.

How to do it…

We're going to make a global random color generator and add random colors to all the objects on the screen by performing the following steps:

  1. Open templates.html, found in your [project root]/client...