Matteo Riva
Matteo Riva

Reputation: 25060

How to handle conditions when using mustache.js

Suppose I have a list of items each one with a property (status) which can have one of these values:

I need to display three different things in the template according to that value. These three things differ in markup and not only value.

Now mustache being logic-less doesn't really provide logic constructs. Only boolean conditions can be "emulated ifs" with sections and inverted sections.

Given that I have 3 different status values, what's the best way to construct the template?

  1. I can add three separate boolean properties and use sections
  2. I can cycle on all the items before rendering and add another property to each item containing the correct markup imported by another template (seems a bit overkill)
  3. other?

Upvotes: 2

Views: 1670

Answers (1)

maxbeatty
maxbeatty

Reputation: 9325

Use Handlebars if you want to add logic to logic-less Mustache

Upvotes: 2

Related Questions