0

In my Grails app I have various images:

/web-app/images/competition/foo bar.png
/web-app/images/competition/foo bar2.png
/web-app/images/competition/foo bar3.png

The name of the image to be displayed is stored in the model that's passed to the GSP. I'm trying to create a link to this using the <r:img> tag provided by the resources plugin. So far I've tried:

<r:img file="competition/${imageName}.png"/>
<r:img file="competition/${imageName.encodeAsHTML()}.png"/>
<r:img file="competition/${imageName.encodeAsURL()}.png"/>

But none of these seem to work. I realise renaming the file would make my life a lot simpler, but sadly this is not possible.

Dónal
  • 185,044
  • 174
  • 569
  • 824

1 Answers1

1

Add the below entry in ApplicationResources.groovy as.

modules = {
    images {
        resource url:'images/competition/foo%20bar.png'
    }
}

and access it in view as

<r:img uri="/images/competition/foo bar.png"/>

or

<r:img file="competition/foo bar.png"/>

You should be able to access the resource.

Note:-
Accessing the resource as
<r:img file="competition/foo%20bar.png"/>

did not work for me. Apparently, I made sure I am not reading from browser cache so I followed the below steps:

  • Tested in Chrome Incognito Mode.
  • Cleared browser cache every time.
  • Tested in Firefox and IE.
  • Cleaned and compiled the project to replicate the issue every time, in case browser was served from the cache.
dmahapatro
  • 49,365
  • 7
  • 88
  • 117
  • Thanks for the response. Unfortunately, the reality is a little more complicated than in my original question. I've updated the question to explain the full horror of my predicament. Any further suggestions would be much appreciated. – Dónal Jul 11 '13 at 07:18