Reputation: 5048
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
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
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
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
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