How work with statements in meteor template

I like to work with meteor, but I have a problem I can't find a solution for.

In the template file I have this code:

<template name="klussenboard">
<h2>Klussen</h2>
  <div class="klussenboard">
     {{#each klus}}
    {{#if status=1}}
    <li>
    <a class="startlink" href="#"><img src="/images/starten.png"></a>
    </li>
    {{/if}}
    {{/each}}
</div>
</template>

This is the js client code

Template.klussenboard.klus = function () {
        return Klussen.find({"status": { $gt: 0 }}, {
        sort: {datum: -1}
    });
};

But this doesn't work. How can I do a statement in a template file?

Looking forward to an answer.

Answers:

Answer

Spacebars (meteor's templating library), much like Handlebars (that it is based on) doesn't execute arbitrary expressions like, say, angular.js's templates.

If you change the statement you're trying to write into a helper method, like so (feel free to pick a better name!):

<template name="klussenboard">
  <h2>Klussen</h2>
  <div class="klussenboard">
    {{#each klus}}
      {{#if isEnabled}}
        <li>
          <a class="startlink" href="#"><img src="/images/starten.png"></a>
        </li>
      {{/if}}
    {{/each}}
  </div>
</template>

You could then define the isEnabled helper in any client side .js file - say, client/klussenboard.js like so:

Template.item.isEnabled = function() {
  return this.status == 1;
}

So, this, in helper functions is

This assumes that you are in a context where status is a variable (which, based on your question, you are)

This would then reactively update whenever the status variable changes.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.