Style variables
What is a style variable?
Moved to Style Variables.
How to use style variables?
Moved to Style Variables.
Using CSS properties XWiki 17.3.0+
Moved to Use CSS Properties.
New CSS properties
Moved to New CSS Properties.
LESS variables
Moved to Use LESS Variables.
Old colorTheme variables
Moved to Use Old ColorTheme Variables.
Migrating from LESS to CSS properties
Moved to Migrate from LESS variables to CSS properties.
Using CSS variables in LESS
Sometimes you want to start migrating a file without being able to move it all at once. In this kind of situation, you'll need to know about how to use CSS variables in a LESS file.
The LESS parser we use in XWiki standard is not maintained enough to ensure a good compatibility with current CSS. It does not work well with CSS variables directly. The usual solution to escape things in LESS works well for most cases: a tilde and the escaped content in between quotes.
:root {
-/**/-navbar-default-bg: ~"var(--brand-primary)";
-/**/-navbar-default-border: ~"color-mix(in srgb, var(--navbar-default-bg), black 6.5%)";
}But, a quirk of the parser is that this syntax does not work when we're trying to use it for an assignation. One hack that's not too bad looking that works for those variable assignations is to add an empty comment block in the middle. It prevents the LESS parser from associating the two dashes together and assume this is the end of an HTML comment. You can see this workaround in the example above.
Migrating from old colortheme variables to CSS variables
There is no "easy" way to do this kind of migration because the old colorTheme variables do not map 1 to 1 to CSS variables. You might want to check how they got mapped to LESS variables to get an idea of CSS properties that have similar values (or just use the CSS properties with the semantics corresponding to your situation
). Those oldColorTheme -> Less variables mappings are available in the variablesInit.vm template.
Once you removed all the old colortheme variables from your stylesheet, you can also remove the call to the colorThemeInit.vm template and don't need to parse it anymore.