0

I have a JSON being passed to a Dust template and want to compare multiple keys for the same value. For example I have a JSON like:

  "data": {
     "abc": "true",
     "xyz": "true",
     "uno": "true"
  }

Is there a way apart from using "IF" condition(it's deprecated), to compare all of them at once?

I don't wanna do

{?data.abc}
  {?data.xyz}
    {?data.uno}
       <DO something when all of them are true>
    {/data.uno}
  {/data.xyz}
{/data.abc}

Is there a better way to do the above conditions?

P.S. for dust-helper version 1.5.0 or lower.

Gautam
  • 108
  • 8

1 Answers1

0

After talking to a few developers and researching a lot, there are no specific dustjs filters designed for such a use case for dust-helper version 1.5.0 or lower.

Having said that, the following code seems to work pretty well,

{@select key=abc}
  {@eq value="true"/}
  {@eq key=xyz value="true"/}
  {@eq key=uno value="true"/}
  {@any}One of them is "true"{/any}
  {@none}None of them is "true"{/none}
{/select}

P.S. I couldn't compare boolean values, but if I pass boolean value true as a string "true", it works perfectly.

Gautam
  • 108
  • 8