switch statement in twig drupal 8
I think there doesn't exist a Switch function in Symfony/Twig. You have to fall back on a standard
{% if condition %}
...
{% elseif condition2 %}
...
{% else %}
...
{% endif %}
Hope I could help..
I was also looking to do a "switch statement" for my view template for Drupal 8, but I couldn't get it to work. I had the following:
{% set rowsLength = rows|length %}
{% switch rowsLength %}
{% case 1 %}
...
{% case 2 %}
...
{% case 0 %}
...
{% endswitch %}
But when uploaded it just gave didn't render and put at that message of "something is wrong". So I ended up using the following "if" statement:
{% set rowsLength = rows|length %}
{% if rowsLength > 0 and rowsLength < 4 %}
{% set nav_size = "small-carousel" %}
{% elseif rowsLength > 4 and rowsLength < 6 %}
{% set nav_size = "medium-carousel" %}
{% else %}
{% set nav_size = "" %}
{% endif %}
Hope it helps.