A
A
Andrey_872017-08-03 16:16:15
Twig
Andrey_87, 2017-08-03 16:16:15

How to convert this construction into twig?

foreach ($languages ​​as $language) {
if(!isset($menu_new[$language['language_id']])) $menu_new[$language['language_id']] = "text";
}
doesn't work like this
{% for language in languages ​​%}
{% if (menu_new[language.language_id] is defined) %} {% set menu_new[language.language_id] = "text" %}{% endif %}
{% endfor %}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
novrm, 2017-08-03
@novrm

Maybe instead of menu_new[language.language_id]
try menu_new.language.language_id?
... and replace menu_new[language.language_id] with menu_new.language.language_id

Z
zooks, 2017-08-06
@zooks

{% for language in languages %}
{% if menu_new[language.language_id] is not defined %}
    {% set menu_new[language.language_id] = "text" %}
{% endif %}
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question