Wednesday, 21 August 2013

PHP/TWIG : for loop to build HTML divs

PHP/TWIG : for loop to build HTML divs

I come from ASP.NET MVC and the following was easy enough to do. I'm
wondering how it can be done with PHP and TWIG.
I want to dynamically build a series of HTML div. A div looks like this:
<div class="grid_gallery-item">
<img src="img/gallery/gallery_grid1.jpg" alt=""/>
<a href="img/gallery/gallery_grid1.jpg"></a>
</div>
Ths src attribute of the image as well as the href of the hyperlink should
be different for every divs. I would like to do it in a for loop, using
the incrementer to change src and href paths.
One more difficulty is that I use assetic (symfony2) for my paths. So the
src attribute and href attribute are actually like:
{{asset('img/gallery/gallery_grid1.jpg')}}
How can I do that ?

No comments:

Post a Comment