Twig: Get variable variables in Twig

Created on 5 Oct 2015  路  5Comments  路  Source: twigphp/Twig

How to get the contents of the variable variables?

in conttoller: $name_1 = "title1"
in template: {% set var = name_ ~ id_point %}

Php analogue: $$var

Thanks.

All 5 comments

You dont.

it's impossible?

You can use an array with a dynamic key, using dynamic names for a variable in Twig is a horrible idea.
Having something like var1, var2 is a good indication your are not using the right technique to solve a problem.

I dislike the "Impossible" word, you can of course, even if that's not recommanded.

{{ _context['name' ~ id_point] }}

Thank you, I understand that this is a bad way.
Unfortunately it is very difficult to alter.

Was this page helpful?
0 / 5 - 0 ratings