Skip to content
Mária Jurčovičová edited this page Sep 17, 2015 · 7 revisions

Less4j makes it possible to configure additional variables from java. Additional variables are added into global scope e.g. they behave as if they would be written at the end of compiled sheet.

// define less sheet
StringSource less = new StringSource("" +
    "div {                            " +
    "    @variable-detached();        " +
    "    color: @variable-color;      " +
    "}                                " +
    "@variable-color: overriden;      " +
    "");
    
// configure additional variables
Configuration configuration = new Configuration();
configuration.addExternalVariable("@variable-detached", "{ detached: ruleset; }");
configuration.addExternalVariable("@variable-color", "green");

// compile
LessCompiler compiler = new DefaultLessCompiler();
CompilationResult compilationResult = compiler.compile(less, configuration);

//print compiled css
System.out.println(compilationResult.getCss());