mhlavacka
mhlavacka

Reputation: 701

Meteor: display different data based on what Session equals

Is there a way to use something similar in Meteor to this

{{#if $.Session.equals 'sessionName' value1}}
  <p> value1 </p>
{{/if}}
{{#if $.Session.equals 'sessionName' value2}}
  <p> value2 </p>
{{/if}}
{{#if $.Session.equals 'sessionName' value3}}
  <p> value3 </p>
{{/if}}

I'm trying to use helpers, but can't get it to work:

{{#if 'helperName' value1}}
  <p> value1 </p>
{{/if}}
{{#if 'helperName' value2}}
  <p> value2 </p>
{{/if}}
{{#if 'helperName' value3}}
  <p> value3 </p>
{{/if}}

Template.name.helpers({
  helperName: function (item) {
    return Session.equals('currentItem', item);
  },
});

onBeforeAction: function() {
  Session.set('currentLastItem', 'value1');
  this.next();
}

And I get error statement that there is no such function as helperName

This is the same principle but used to render different data based on the current route - Meteor: Change the class of link on click

Upvotes: 1

Views: 41

Answers (1)

Brett McLain
Brett McLain

Reputation: 2010

This would allow you to use the syntax you used above:

https://atmospherejs.com/raix/handlebar-helpers

Upvotes: 1

Related Questions