Nans Thomas Nans Thomas - 4 months ago 16x
PHP Question

How to pass #text in Twig

I have a problem with the API & Twig. I have this array and want to get the image URL, so I put this into my Twig file:

{{ xxxx.image[0]['#text'] }}

This is my array:

[0] => stdClass Object
[name] => David Bowie
[listeners] => 3091283
[mbid] => 5441c29d-3602-4898-b1a1-b77fa23b8e50
[url] =>
[streamable] => 0
[image] => Array
[0] => stdClass Object
[#text] =>
[size] => small

But I have this Twig error:

Impossible to access a key "#text" on an object of class "stdClass"

How can I fix this?


You can use the TWIG attribute function as follow:

{{ attribute(xxxx.image[0], '#text') }}

Hope this help