I need to configure some URLs for my Play application so I added them to application.conf:
application.url="http://www.mydomain.com"
application.url.images="http://www.anotherdomain.com"
application.url.images.logo="${application.url.images}/logo.png"
...
Here below is the code I use in my views to access the entries above:
@(title: String)
@import play.api.Play.current
<!DOCTYPE html>
<html>
...
<img src="@{ currrent.configuration.getString("application.url.images.logo") }" />
...
</html>
Well... I'm getting crazy since whenever I run the application I always get the following error message:
/home/j3d/Projects/test-app/conf/application.conf: 14-19: application.url.images.logo has type OBJECT rather than STRING
Any idea? Am I missing something? Or is it a bug?
Thank you very much.
Config in Typesafe Configuration library used in Play represents JSON-like structure. Dot notation is syntax sugar to create nested objects ({ ... } in JSON). For example:
application.url="http://example.com"
application.images.logo="http://example.com/img/1.png"
application.images.header="http://example.com/img/3.png"
is equivalent to following JSON:
{
"application": {
"url": "http://example.com",
"images": {
"logo": "http://example.com/img/1.png",
"header": "http://example.com/img/3.png"
}
}
}
In your example you first assign string to application.url, then trying to add keys to it (key url in application.url.images), like it is JSON object, not string. I don't know exact behavior of Typesafe Config in this case, and why it don't raise error immediately when reading config file.
Try rearranging hierarchy of config keys, i.e.:
application.url.prefix="http://www.mydomain.com"
application.url.images.prefix="http://www.anotherdomain.com"
application.url.images.logo="${application.url.images}/logo.png"
Here application.url will be object with keys prefix and images, and application.url.images will be object with keys prefix and logo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With