How to "break" a loop in Twig?
I want to use break
in Twig templating engine.
{% for key, db_staff_language in db_staff_languages %}
{% for staff_language in model_data.staff_languages %}
{% if staff_language.id == db_staff_language.id %}
<option value="{{db_staff_language.id}}" selected="selected">{{db_staff_language.staff_languages_data_translation[0].value}}</option>
{% else %}
<option value="{{db_staff_language.id}}">{{db_staff_language.staff_languages_data_translation[0].value}}</option>
{% endif %}
{% break %} {# <-- Not working #}
{% endfor %}
{% endfor %}
Since I couldn't solve the problem with Twig, I also tried other things, for example:
-----------------------------------------------
{% autoescape true %}
<?php echo 'test' ?>
{% endautoescape %}
-----------------------------------------------
{% php %}
<?php echo 'test' ?>
{% endphp %}
-----------------------------------------------
{% verbatim %}
<?php echo "test"; ?>
{% endverbatim %}
-----------------------------------------------
{{ raw }}
<?php echo "test"; ?>
{{ endraw }}
-----------------------------------------------
Is there a solution to this problem?
+3
source to share
1 answer
Twig does not include a break statement. According to the official manual, the equivalent statement for the + if condition .
+4
source to share