dsf323233323332 2016-06-07 13:40
浏览 21
已采纳

如何在Twig中传递#text

I have a problem with the Last.fm 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:

   Array
(
    [0] => stdClass Object
        (
            [name] => David Bowie
            [listeners] => 3091283
            [mbid] => 5441c29d-3602-4898-b1a1-b77fa23b8e50
            [url] => http://www.last.fm/music/David+Bowie
            [streamable] => 0
            [image] => Array
                (
                    [0] => stdClass Object
                        (
                            [#text] => http://img2-ak.lst.fm/i/u/34s/937d62bb145040b9b709319c1e680037.png
                            [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?

  • 写回答

1条回答 默认 最新

  • dqblm40280 2016-06-07 13:45
    关注

    You can use the TWIG attribute function as follow:

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

    Hope this help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型