Using Dust.js (LinkedIn version) `@eq` to match multiple values

2.4k views Asked by At

Note that I am using LinkedIn's version of Dust.js, along wiht their helpers.

I have a Dust.js template where I need to determine if a value at a certain key is one of three potential values.

{@select key="{movie.type.name}"}
  {@eq value="Episode|Season|Show"}
    <span data-tag="show_level" class="qc_still_info">{@translate key="label.show_level_tag"/}</span>
  {/eq}
  {@default}
    <span class="qc_still_info">{@translate key="label.cannot_tag_show_level"/}</span>
  {/default}
{/select}

{@eq value="Episode|Season|Show"} is pseudo-code for matching Episode, Season or Show. I want to discover the most idiomatic Dust.js syntax for achieving this goal.

If the data is this

{
  movie: {
    type: {
      name: 'Season'
    }
  }
}

or

{
  movie: {
    type: {
      name: 'Episode'
    }
  }
}

or

{
  movie: {
    type: {
      name: 'Show'
    }
  }
}

..then I want the following output

<span data-tag="show_level" class="qc_still_info">Add a Show Level Tag</span>
1

There are 1 answers

0
smfoote On BEST ANSWER

@any is a relatively new Dust helper that should solve the problem for your (documented here: http://www.dustjs.com/guides/dust-helpers/#select-helper). Using the @any helper, your code would look like

{@select key=movie.type.name}
  {@eq value="Episode"/}
  {@eq value="Season"/}
  {@eq value="Show"/}
  {@any}
    <span data-tag="show_level" class="qc_still_info">{@translate key="label.show_level_tag"/}</span>
  {/any}
  {@none}
    <span class="qc_still_info">{@translate key="label.cannot_tag_show_level"/}</span>
  {/none}
{/select}