yoda
yoda

Reputation: 10981

Twig complex array conversion

How do I convert such logic into Twig 2.x?

<?php if (isset($pricerunner_category[$category['category_id']])) { echo $pricerunner_category[$category['category_id']]; } ?>

Upvotes: 1

Views: 45

Answers (1)

aknosis
aknosis

Reputation: 4308

Should be possible with the attribute function.

https://twig.symfony.com/doc/2.x/functions/attribute.html

{% if attribute(pricerunner_category, category.category_id) is defined %}
    {{ attribute(pricerunner_category, category.category_id) }}
{% endif %}

Not sure if the is defined is necessary or not, added it based on the docs.

Upvotes: 1

Related Questions