Search code examples
grailsgroovygspgrails-config

how to set value in Config.groovy and get different value for same parameter according to environment on gsp in Grails?


I have a situation. I want to set one value to some parameter in Config.groovy in my Grails project. This parameter should have different value for each environment, i.e. for dev environment it is like abc = "devValue", for test environment like abc="testValue" and for production environment like abc="prodValue". and then I want to set that value as a hidden field value on gsp page according to running environment.


Solution

  • There's already an example of this in the Config.groovy that's generated for you:

    environments {
       development {
          grails.logging.jul.usebridge = true
       }
       production {
          grails.logging.jul.usebridge = false
       }
    }
    

    so you can just add your setting there:

    environments {
       development {
          grails.logging.jul.usebridge = true
          abc = "devValue"
       }
       test {
          abc = "testValue"
       }
       production {
          grails.logging.jul.usebridge = false
          abc = "prodValue"
       }
    }