Display images in gsp (grails)

I am very new to grails. I am making one sample project for loading and displaying images. Now my project uploads the images and saves it to the images.Now directory I want to display all the images stored in the "image" directory. I do not know how to write gsp code to display all the images.

To display the images, I wrote the following code on list.gsp.

My gsp code:

<g:each in="${imageList}" var="image"> <img src="${createLinkTo(dir: 'images', file: '1.jpg')}" alt="Grails"/> </g:each> 

imageList has file names in the image directory.

In the second line I want to put the file name instead of "1.jpg".

Can someone tell me how to display images.

thanks

+7
frameworks grails
source share
3 answers

If your imageList has a list of image objects, try the following

$ {createLinkTo (dir: 'images', file: image.filename)}.

If your imageList is like this ['1.jpg', '2.jpg', '3.jpg'] try the following

 **${createLinkTo(dir: 'images', file: image)}** 
+4
source share

Depending on what is in your imageList, you can do:

 <g:each in="${imageList}" var="image"> <img src="${createLinkTo(dir: 'images', file: image.filename)}" alt="Grails"/> </g:each> 
+2
source share

Assuming your imageList is like ['1.jpg', '2.jpg', ...] , your createLinkTo should look like this:

 ${createLinkTo(dir: 'images', file: image)} 

Since you have already defined the iterator variable as an “image”. If this does not work, this can help clarify what is in the contents of your imageList collection.

+2
source share

All Articles