在 smarty 中打印数组中的子数组(foreach)
我正在尝试使用 smarty 模板引擎打印数组中的子数组。假设我有一个像这样的数组结构:
Array
(
[0] => Array
(
[directory] => One Day As A Lion - 2011-03-01/
[source_notes] => iRiver
[recording_type] => Audience
[type] => Audio
[source_type] => MP3
[fileList] => Array
(
[0] => 09 One Day As A Lion.mp3
[1] => 01 Intro.mp3
[2] => 05 Ocean View.mp3
[3] => 04 Swashbuckler.mp3
[4] => One Day As A Lion - 2011-03-01 - Prince Bandroom, Melbourne, Australia.jpg
[5] => 10 Peart Plus.mp3
[6] => 06 Rockers.mp3
[7] => 03 Last Letter.mp3
[8] => 07 Swampy.mp3
[9] => 02 If You Fear Dying.mp3
[10] => 08 Wild International.mp3
)
)
)
我究竟如何获取包含要在 smarty 中打印的文件名的数组?目前我在 smarty 中有一个 foreach 循环,如下所示:
{foreach $sources as $sourceInfo}
{strip}
Recording Type: {$sourceInfo.type} : {$sourceInfo.recording_type}<br>
Source : {$sourceInfo.source_notes}<br>
{/strip}
{/foreach}
我不确定如何实现第二个 foreach 循环。有人有什么建议吗?我对文档有点困惑,因为似乎有两种嵌套 foreach 循环的方法,其中一种似乎已被弃用。 foreach 循环是最好的方法吗?或者 smarty 中还有其他推荐的方法吗?任何反馈将不胜感激。谢谢!
I'm trying to print a subarray in an array with the smarty template engine. Say I have an array structure like this:
Array
(
[0] => Array
(
[directory] => One Day As A Lion - 2011-03-01/
[source_notes] => iRiver
[recording_type] => Audience
[type] => Audio
[source_type] => MP3
[fileList] => Array
(
[0] => 09 One Day As A Lion.mp3
[1] => 01 Intro.mp3
[2] => 05 Ocean View.mp3
[3] => 04 Swashbuckler.mp3
[4] => One Day As A Lion - 2011-03-01 - Prince Bandroom, Melbourne, Australia.jpg
[5] => 10 Peart Plus.mp3
[6] => 06 Rockers.mp3
[7] => 03 Last Letter.mp3
[8] => 07 Swampy.mp3
[9] => 02 If You Fear Dying.mp3
[10] => 08 Wild International.mp3
)
)
)
How exactly would I get the array containing the filenames to print in smarty? Currently I have a foreach loop in smarty that looks like:
{foreach $sources as $sourceInfo}
{strip}
Recording Type: {$sourceInfo.type} : {$sourceInfo.recording_type}<br>
Source : {$sourceInfo.source_notes}<br>
{/strip}
{/foreach}
And I'm not sure how to implement a second foreach loop. Does anyone have any suggestions? I'm a little confused with the documentation since there seems to be two methods of nested foreach loops, one of which seems to be deprecated. Is a foreach loop the best way to do it, or is there another recommended way in smarty? Any feedback would be much appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需添加另一个 foreach:
Simply add another foreach: