Warning: this post is old and might not reflect the current state of the art

Here’s a simple example on combining Session variables and template helpers to achieve a simple case of selecting the current comment selected in a list.

In our template.html file:

<template name="main">
  {{#each comments}}
    {{> comment}}

<template name="comment">
  <div class="{{#if selected}}selected{{/if}}">

In template.js:

Session.set('selectedComment', null);

  comments: function() {
    return Comments.find();

  selected: function() {
    return Session.equals('selectedComment', this._id);

  'click div' : function(e, t) {
    Session.set('selectedComment', this._id);

In this case any time I click a comment, that comment becomes the selected comment, and we can show it full-size, fetch the other comments made by the user or do some other fancy stuff.