My controller sends to Twig the following associative array in a variable called 'petition';
Array
(
[0] => stdClass Object
(
[id] => 1
[doctype] => "somedoc"
[nrdoc] => "99"
[datadoc] => "2015-01-01"
)
[1] => stdClass Object
(
[id] => 2
[doctype] => "otherdoc"
[nrdoc] => "100"
[datadoc] => "2015-01-01"
)
)
Then, in my Twig template (view) I'm doing this:
{% for id in petition %}
{% if id.doctype == 'somedoc' %}
{{id.nrdoc}} / {{id.datadoc}}
{% else %}
UNDEFINED!
{% endif %}
{% endfor %}
The problem is that I can't figure out the logic of how to output "UNDEFINED!" only once, if the doctype != "somedoc" when there are other key->value elements in the array. The way I'm doing it, it will output "UNDEFINED!" everytime the script loops...
Thank you in advance for your help
Gabriel