RE: [SMARTY] trouble with arrays in template
| From: | Erich Beyrent | Date: | Wed, 23 Jul 2003 22:26:52 +0000 |
| Subject: | RE: [SMARTY] trouble with arrays in template | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9952@lists.php.net to get a copy of this message | ||
> Hi there,
>
> I am trying to pass in the following array to my template:
>
> $gallery_dir = $DOCUMENT_ROOT.'/photos/gallery/';
> $smarty->assign('PhotoArray',
> array('link' => $gallery_dir.'yellow/Bikes0.jpg'),
> array('link' => $gallery_dir.'yellow/Bikes1.jpg'),
> array('link' => $gallery_dir.'yellow/Bikes2.jpg'),
> array('link' => $gallery_dir.'yellow/Bikes3.jpg'),
> array('link' => $gallery_dir.'yellow/Bikes3.jpg'),
> array('link' => $gallery_dir.'yellow/Bikes3.jpg')
> );
>
> And then in my template, loop through them:
>
> <!-- Template code -->
> <table border="0" cellspacing="0" cellpadding="5">
> {section name=i loop=$PhotoArray}
> <tr>
> <td><img src="{$PhotoArray[i].link}"</td>
> </tr>
> {/section}
> </table>
>
>
>
> However, none of the images are loading, and none of the template code
> is showing up at all.
>
> What have I done (or not done), and how do I fix it?
>
> Thanks for your help!
>
> -Erich-
>
> You need a numerically indexed array. Just do:
>
> $smarty->assign( 'PhotoArray', array(
$gallery_dir.'yellow/Bikes0.jpg',
>... $gallery_dir.'yellow/Bikes3.jpg' ));
>
> and dispense with the "link":
>
> <img src="{$PhotoArray[i]}">
>
> You forgot the closing angle bracked on your IMG tag, btw.
>
> cheers,
>
> Travis
Thanks Travis. But what if I want to also associate alt text with the
image in the array? Do I really need to have another array containing
the alt text with indexes corresponding to the values in the links
array?
-Erich-