首页 > 解决方案 > How can I use a bool and bool condition in a mustache template?

问题描述

I am looking to use two conditions together to handle a display. If both a and b are true, then show something.

In JavaScript, we would write: if (a && b) { ... }

Moustache

{{#(one && two)}} // or #one && #two
  <p>foobar</p>
{{/(one && two)}}

JSON

{
  "one": "OK",
  "two": "Yes"
}

标签: booleanmustache

解决方案


请记住

if (a && b) {
}

是相同的

if (a) {
    if (b) {
    }
}

所以你可以这样写你的 Mustach 模板:

胡子

{{#one}}
{{#two}}
  <p>foobar</p>
{{/two}}
{{/one}}

推荐阅读