PHP allow in array to be a space in the key like this:
(dump from symfony2)
array:9 [▼
"Guest" => 1
"Vip Client" => 2
"Super admin" => 3
]
So how can I access the data by key in Twig? Normaly for the Guest it will be {% array_name.Guest %} this will not work {% array_name['Vip Client'] %}
You can use attribute function
{{ attribute(array_name, 'Vip Client') }}
As suggested here: http://twig.sensiolabs.org/doc/templates.html#variables
You can access like this: {{ array_name['Guest'] }}
if you want to print. If you want to use it if condition you can write
{% if array_name['Vip Client'] == 1 %} {{'Vip Client'}} {% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With