php - Verify if is in array in twig template -
i have question, it's possible make in_array in twig template? example have array call acolors colors of 1 product :
array[ 0 => "1" 1 => "2" ]
and have class in libraries folder :
class colors{ public static $acolors = array( '1' => 'white', '2' => 'black', '3' => 'yellow', '4' => 'red', '5' => 'green', '6' => 'blue', ); }
now want verify if values of array colors of product = keys of general array colors, , tried in .twig :
{% key,val in acolors %} {% if val in colors::acolors %} {% endfor %}
but not work. exist solution? please me. can me? thx in advance!!!
twig not intended run php code in it. official position of twig developers: twig template engine , thing templating, doesn't know classes, static class properties , other php-only stuff. options have are:
- pass array context variable, global or local, (preferred way).
- create extension or twig function access class property internally (this goes against twig principles, works, though i'll use line of answer warn not it).
Comments
Post a Comment