Ashish Ranjan
Ashish Ranjan

Reputation: 12960

How can I use nested structures in meteor spacebars?

In the following example I have registered an helper "currentUser" in a file utils.js in the lib folder of the client. I am trying to align the messages right or left if the condition satisfies.

<template name="chatMessages">
{{#each chatMessages}}
    {{#if currentUser {{email}}}}
        <b style="float:right;">{{message}}</b>
        <br>
    {{else}}
        <b style="float:left;">{{message}}</b>
        <br>
    {{/if}}
{{/each}}

The helper code is:

Template.registerHelper("currentUser", function(input) {
    return Session.get("userMail") === input;
});

Upvotes: 0

Views: 72

Answers (1)

Michel Floyd
Michel Floyd

Reputation: 20256

Don't put the parameter to the helper inside curly braces, i.e. instead of:

  {{#if currentUser {{email}}}}

use

  {{#if currentUser email}}

Assuming that the variable email is defined in the data scope of the helper! (you don't show that part).

Upvotes: 3

Related Questions