Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access dynamic variable names in twig?

Tags:

I have some variables in twig like

placeholder1
placeholder2
placeholderx

To call them, I am looping through the array of objects "invoices"

{% for invoices as invoice %}
    need to display here the placeholder followed by the invoice id number
    {{ placeholedr1 }}
like image 273
Milos Cuculovic Avatar asked Jul 11 '14 12:07

Milos Cuculovic


1 Answers

I just had the same issue - and using this first answer and after some additional research found the {{ attribute(_context, 'placeholder'~invoice.id) }} should work (_context being the global context object containing all objects by name)

like image 107
Mathieu Jamot Avatar answered Sep 17 '22 19:09

Mathieu Jamot