Choose / switch / else-if statement

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Choose / switch / else-if statement

meyertee
Hello,

do you have any plans to implement some kind of switch statement, or is there something already that I'm missing?

Something along these line (jsp-like):
<div th:choose="choose">
  <div th:when="${a=='a'}"><div/>
  <div th:when="${a=='b'}"><div/>
  <div th:otherwise="otherwise"><div/>
</div>

For me it would be especially helpful when including fragments based on some condition, eg:
<div th:choose="choose">
  <div th:when="${media == 'video' or media == 'audio'}" th:substituteby="media :: player"><div/>
  <div th:when="${media == 'image'}" th:substituteby="media :: image"><div/>
  <div th:otherwise="otherwise" th:text="${text}"><div/>
</div>

That'd put the when attribute quite high on the precedence list though...

Best, Thomas.
Reply | Threaded
Open this post in threaded view
|

Re: Choose / switch / else-if statement

danielfernandez
Administrator

Hi,

There currently is no equivalent to the "th:choose" you propose in the Standard Dialects.

Nevertheless, your syntax looks quite good. I might think about adding a similar feature in next versions... would you add a Feature Request ticket for this?

Thanks a lot,

Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: Choose / switch / else-if statement

meyertee
Feature request added, that'd be brilliant :)
Thank you, Thomas.