Search code examples
phptwigtwig-extension

how to use image in for loop in Twig?


i have the address of images in the array and i want to load 3 image from that source

my code :

 {% for address in image.address %}
  <img src="??">

  {% endfor %}"

what should I write in the Src in img tag?


Solution

  • Finally its better to do this :

    <img src="{{ asset(news.address[i]) }}">
    

    and we the array are sth like this :

    $news = array(
    'address'=>array('bundles/Hippomain/frontend/img/img1.jpg',),
    );

    and in this way we can load each image we have in the array easily !