Variables in XML to use with NiftyGUI


How can I define some variables inside nifty’s xml file and how to use them later?

In my case I want to define some colors as a variable so to be able to change them all just by changing the variable’s value.

I know probably the first answer you would like to write me will be “use styles”, but that is not what I am asking for :slight_smile:

It is really. Set up a style with the colours you want, change the style, change everywhere.

You could probably also do it using the translation stuff - put the colour codes in a properties file and use that.

Thee is an embed variable system explained in the Nifty bible doc

You can refer to a controller method in any xml attribute

for example :


<panel width="${CALL.getWidth()}" />


then you just have to implement a getWidth() method in your controller. The method has to return a String but not sure it’s mandatory.

You can refer to a controller method in any xml attribute

So.. only from controller class? no way to define them in xml directly not using styles?

Adding to Nehons answer:

Psalm “SPECIAL XML MARKUP” on page 18 in the bible describes all of the currently supported variables in XML.

Besides these variables (read the paragraph!) and styles there is currently no other way to define or use variables.