roeygol
roeygol

Reputation: 5048

Grails - how to access properties file from GSP

I need to have access to my properties file from GSP file to get one of it's values. I tried to find example over the web, but I couldn't. This is a file which I created and not Grails.

Thanks!

Upvotes: 3

Views: 3645

Answers (4)

Rahul Mahadik
Rahul Mahadik

Reputation: 12291

From grails controller and gsp file, you can access your yml file properties using GrailsApplication object:

${grailsApplication.config.get('YOUR_PROPERTY_NAME)}

Upvotes: 2

Steve
Steve

Reputation: 1467

If you are reading simple properties it sounds like what you want is externalized configuration

To use it in a GSP (if you really need to, but not recommended from a GSP):

${Holders.config.myPropertyKey}

Upvotes: 0

Rafael
Rafael

Reputation: 2676

you can access aaplicationContext from the GSP ... so you can access any configuration property.

Just look at this entry from Mr. Haki: http://mrhaki.blogspot.com.es/2011/11/grails-goodness-get-grailsapplication.html

Upvotes: 1

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27255

If the properties file is under grails-app/i18n/ (it can be your own properties file, doesn't have to be one of the default ones) then you can access property values from the property file in a GSP using the message tag. See http://grails.org/doc/latest/ref/Tags/message.html.

Upvotes: 0

Related Questions