2017-10-25 4 views
1

このようなロジックをTwig 2.xに変換するにはどうしたらいいですか?Twig complex array conversion

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

答えて

1

attribute機能で可能である必要があります。

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 %} 

ないis definedが必要であるかどう必ず、ドキュメントに基づいてこれを追加しました。