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 the Session object


The Session object is a global client-side object, and as such, is part of the client model. Though it's not part of any collection, the Session object can be used in a reactive context, which means you can use it to make reactive methods rerun whenever it is changed. This recipe will show you how to use the Session object to update the elements on your page.

Getting ready

You will need to have Meteor installed and a project created. To create a standard project file structure, please see the Setting up your project file structure recipe in Chapter 1, Optimizing Your Workflow. A quick default project will work just as well for this recipe.

How to do it…

To use the Session object, proceed with the following steps:

  1. Open the main.js file in your client's scripts folder ([project root]/client/scripts/main.js) and add a greeting helper to the beginning of Template.hello.helpers, as follows:

    Template.hello.helpers({   greeting: function() { return Session.get('greeting')||'Welcome...