Search code examples
phparrayssmarty

Loop over an array and image


I have links to my images and I have put them in an array. I would like to know how to loop my images using the existing links in my array. I would want something like this to show in smarty:

<img src="meat.jpg" />
<img src="chicken.jpg" />
<img src="pork.jpg" />

This is my code now private

$_arr = array(0 => "meat.jpg",
              1 => "chicken.jpg",
              2 => "pork.jpg"
);

Solution

  • Look into manual you simply need to pass $_arr to Smarty and use foreach loop like this:

    {foreach from=$_arr item=src}
        <img src="{$src}"/>
    {/foreach}