Can dotless query string override existing variables?

423 views Asked by At

Inside ASP.net I'm serving a dynamic less stylesheet with dotless. I'm using a query string to pass in the variables.

<link rel="stylesheet" href="~/Content/style.less?&color1={{var1}}&color2={{var2}}>

The variables are already declared in LESS (color1: red, color2: blue), I would like to override these values if they are passed in the query string. This does not work right now because dotless actually prepends the variables from the query string, and less uses the last declared variable.

I see two options, but I don't how to achieve these:

  1. Append the variables instead of prepend them. This is how dotless does the prepending: https://github.com/dotless/dotless/blob/master/src/dotless.Core/Engine/ParameterDecorator.cs
  2. Set the less variables color1 and color2 as optional - only if they're not set before. Something like:

    color1: color1 || red;
    

    Does something like this exist in LESS (/dotless)?

1

There are 1 answers

0
Bass Jobsen On

Less do not have the option to set default values for variables, see http://lesscss.org/features/#variables-feature-default-variables for the reason that you don't need them, already mentioned by you the last declaration wins (and Less uses Lazy Loading).

But on https://github.com/dotless/dotless/wiki/Parameters i found:

-v --disable-variable-redefines - Makes variables behave more like less.js, so the last variable definition is used

Setting this option to false should fix your issue:

<dotless disableVariableRedefines="false" />