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!

图片转代码服务由CSDN问答提供 功能建议

我使用的是使用Smarty的CMS,我对Smarty并不熟悉。 我可以访问这样的数组值: {{$ data.video.title}}

我需要访问视频信息但遇到了这个问题:

  [formats] => 数组
(
 [.mp4] =>数组
(
 [后缀] => .mp4 
 [维数] =>数组
(
 [0] => 1280 
  [1] => 720 
)
 
 [持续时间] => 330 
 [duration_string] => 5:30 
 [duration_array] =>数组
(
 [分钟] =  > 5 
 [秒] => 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] ​​=> 
)
 
)
    
 
 

我想知道如何访问[.mp4]值,因为它 从一个导致问题的时期开始。 我尝试了很多变体,例如:

  {{$ data.formats..mp3.file_size_string}} 
 
 {{$ data.formats [.mp3]。  file_size_string}} 
 
 {{$数据。[格式] [MP3] [file_size_string]}} 
   
 
 

等... \ n

非常感谢任何帮助!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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条)

相关推荐 更多相似问题