M
M
Maxim2015-10-02 23:30:21
symfony
Maxim, 2015-10-02 23:30:21

Is it possible to use switch inside for in twig?

seemingly simple design:

{% for item in votes %}
<div class="col-sm-6 col-md-4">
  <div class="thumbnail">
    <img src="http://placehold.it/320x240" alt="...">
          		<div class="caption">
        <h3>{{ item.caption }}</h3>
        <p>{{ item.description }}</p>
        <p><a href="{{ path('vote_view', {'id':item.id}) }}" class="btn btn-primary" role="button">Открыть</a> 
        {% switch item.status %}
          {% case "text" %}
          <span class="label label-default">Не готово</span>
        {% endswitch %}
        </p>
      </div>
    </div>
  </div>
{% else %}
  <p>Нет записей для отображения</p>
{% endfor %}

Unexpected tag name "switch" (expecting closing tag for the "for" tag defined near line 27)

Line 27 is the second one here.
Isn't it possible to use nested constructs?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2015-10-02
@maxpointn2point

Twig does not support the {% switch %} tag. Use if/elseif instead.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question