lordZ3d
lordZ3d

Reputation: 601

How to access variable in TWIG which starts with special character

So i have an array in PHP which looks like the one bellow:

array(
  'data' => array(
    '#els' => 1
  )
);

So to access it you would normally do $variable['data']['#els'] which is no problem for PHP, but when i try to access it in TWIG like so {% set els = items.content.data.#els %} i get an error as the els variable has a pound symbol at the beggining, if i remove the pound symbol from the array, i can easily access it in twig with items.content.data.els but i can't do that as that pound symbol is important, so how i can access the #els variable in TWIG?

Upvotes: 1

Views: 1715

Answers (1)

Sergey Podgornyy
Sergey Podgornyy

Reputation: 708

Try this syntax, as described in docs:

{% set els = items.content.data['#els'] %}

Upvotes: 2

Related Questions