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 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)