duandao8607 2014-11-19 21:22
浏览 42
已采纳

当密钥以句点开始时,如何在smarty中访问数组值?

I am using a CMS that uses Smarty, I am not that familiar with Smarty. I can access array values like this: {{$data.video.title}}

I need to access video information but came across this issue:

[formats] => Array
    (
        [.mp4] => Array
            (
                [postfix] => .mp4
                [dimensions] => Array
                    (
                        [0] => 1280
                        [1] => 720
                    )

                [duration] => 330
                [duration_string] => 5:30
                [duration_array] => Array
                    (
                        [minutes] => 5
                        [seconds] => 30
                    )

                [file_size] => 51928676
                [file_size_string] => 49.52 Mb
                [timeline_screen_amount] => 0
                [timeline_screen_interval] => 0
                [file_name] => 5.mp4
                [file_path] => 8ad883ae4989f1aaf1da077bf56d9495/0/5/5.mp4
                [timeline_directory] => 
            )

    )

I would like to know how I can access the [.mp4] values, since it begins with a period it causes problems. I have tried many variations such as:

{{$data.formats..mp3.file_size_string}}

{{$data.formats[.mp3].file_size_string}}

{{$data.[formats][.mp3][file_size_string]}}

etc...

Any help would be greatly appreciated!

  • 写回答

2条回答 默认 最新

  • drhwb470572 2014-11-20 02:57
    关注

    I asked the CMS support for a solution, they provided the following in case anyone else needs to know how to do this:

    You have to assign an extra variable:

    {{assign var="postfix" value=".mp3"}}
    {{$data.formats[$postfix].file_size_string}}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题