Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use twig object variable with at-sign @ inside

I send from Symfony object which contains at-sign @ in variable. Object name is invoice and with {{ dump(invoice) }} in twig template I see object and parameter with path:

invoice[0].banSpojDod@showAs

But I dont know how to get value of this banSpojDod@showAs because there is at-sign @.

Could you help me someone please?

like image 622
Radek Drlik Avatar asked Dec 09 '25 14:12

Radek Drlik


2 Answers

You could try with The attribute function can be used to access a "dynamic" attribute of a variable:

{{ attribute(invoice[0], 'banSpojDod@showAs') }}

Hope this help

like image 104
Matteo Avatar answered Dec 11 '25 13:12

Matteo


Ok thanks. Problem was that I used it in loop, and some parameters not exists. I needed to add exist conditions. So my final code works:

{% for f in invoice %} {% if attribute(f,'banSpojDod@showAs') is defined %} {{ attribute(f,'banSpojDod@showAs') }} {% endif %} {% endfor %}

like image 27
Radek Drlik Avatar answered Dec 11 '25 14:12

Radek Drlik