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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?