Constants

Cadaxo UI5 Snippets #1 – How to define constants

During the work on some Freestyle UI5 Apps I always look for a way how to save constants in Frontend. I would like to share following practice with you, which I use currently.

Define JSON File with Constants

I am going to create a new File in my project root folder. In this file all constant and values will be stored as a JSON Object.

/webapp/model/constants.json

   

Define JSON Model in manifest.json file

I my project manifest.json, I am going to define a new JSON Model with created JSON file in URI

Using Constants in View

From now on it is possible to use the constant model in View:

Using Constants in Controller

And of course also in Controllers. For example like this:

Let me know how you save constants in Frontend or leave a comment if you found this blog post useful!

Posted in Allgemein, Beratung, Cadaxo UI5 Snippets, User Experience and tagged , , , .