Frank Zinner bio photo

Frank Zinner

I'm a passionated senior software developer ...

Twitter Facebook LinkedIn Github Xing

Play2 - Iterating over images in Play2 templates with the Asset-Controller

You can iterate over images in Play2 templates whith the help of Tuples and the zipWithIndex function like this:

	@for((i, index) <- (1 to 6).zipWithIndex; image = "image" + (index + 1) + ".jpg") {     
		@if (index == 0) { 
			<img src=""images/pfeil-links.gif")" alt=""/> 
		<img src=""images/" + image)" alt="Hintergründe"/>                
		@if (index == 5) { 
			<img src=""images/pfeil-rechts.gif")" alt=""/> 

zipWithIndex gives you a Tuple with an index starting at 0. In the comprehensive-for-loop you can use the index in the asset-path to concatenate images. The path can be used like this:"path-to-images/" + variable)