[partially solved] JS switch equivalent in Spacebars


#1

Is it possible to realize [JS switch equivalent][1]
[1]: http://www.w3schools.com/js/js_switch.asp
in Spacebars syntax? Like:

{{#switch color}}
  {{#case red}} {{> redTemplate}} {{/case}}
  {{#case blue}} {{> blueTemplate}} {{/case}}
{{/switch}}

#2

Doesn’t answer your question, but you can have the switch in a helper instead and do something like:

{{> Template.dynamic template=mySwitchHelper}}

#3

Guess I’ll have to stick with multiple If’s for now…

{{if equals color red}}
  {{>redTpl}}
{{#if}}
{{if equals color blue}}
  {{>blueTpl}}
{{#if}}

#4

Dynamic templates work well. We have been using it. It is less clunky and more manageable than the multiple ifs in code.
Spacebars has a goal to reduce code in templates and push as much as possible into helpers/JS. So, using dynamic templates would be the right solution.