|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
mark Smarty Rookie
Joined: 17 Dec 2003 Posts: 5
|
Posted: Wed Dec 17, 2003 12:20 pm Post subject: foreach help |
|
|
Hi, I am totally new to Smarty. I am confused on using foreach loops. Does anyone know how to convert this into smarty?
[php:1:a94befb672]
foreach($arr['content'] as $v) {
echo $v['url'];
echo $v['caption'];
}
[/php:1:a94befb672] |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Dec 17, 2003 12:30 pm Post subject: |
|
|
Code: |
{foreach from=$arr.content item=v}
{$v.url}
{$v.caption}
{/foreach}
|
|
|
Back to top |
|
mark Smarty Rookie
Joined: 17 Dec 2003 Posts: 5
|
Posted: Wed Dec 17, 2003 1:22 pm Post subject: |
|
|
thanks for the quick reply. am i doing this correctly? here is my code:
[php:1:6adf98d057]
// php file
include 'libs/Smarty.class.php';
$smarty = new Smarty;
$smarty->assign('arr', $n4s['content']);
$smarty->display('template.tpl');
[/php:1:6adf98d057]
Code: |
// smarty file
{foreach from=$arr.content item=v}
{$v.url}
{$v.caption}
{/foreach}
|
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Dec 17, 2003 1:28 pm Post subject: |
|
|
i think you have to *either* change the assign to
$smarty->assign('arr', $n4s);
*or* change the foreach to:
{foreach from=$arr item=v}
in your example you are accessing $n4s['content']['content'] |
|
Back to top |
|
mark Smarty Rookie
Joined: 17 Dec 2003 Posts: 5
|
Posted: Wed Dec 17, 2003 2:54 pm Post subject: |
|
|
{foreach from=$arr item=v} worked. thank you very much. this is great. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|