0

How can I change the value from a LESS variable (#333) with ASP.NET

@color: #333;

.logo {
    color: @color;
}
.div {
    background: @color;
}

I'm trying to dynamicaly edit a variable value in a LESS-file using the 'Code Behind' so that when the variable @color get changed using coding, all the elements using that variable will also change.

... codebehind > change @color = #666;
Sam
  • 1,303
  • 3
  • 23
  • 41
  • You can do it with less.js see this SO thread http://stackoverflow.com/questions/7823204/dynamically-changing-less-variables – Jenish Rabadiya May 21 '15 at 09:40
  • Thanks. So using the less.modifyVars I can change the LESS variable, but how can I combine this so that the value goes from asp.net > modifyVars > variable? – Sam May 21 '15 at 09:56

1 Answers1

1

I think it depend how you do compile your Less code.

When your are using .less you can not use modifyVars by default. modifyVars requires lazy loading and last declaration wins. .less got the disable-variable-redefines option:

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

In Less you can put a variable definition afterwards which overrule all earlier definitions due to lazy loading and last declaration wins. See also

modifyVars does not else than putting the variable definition afterwards.

When you are compiling your code node-less (web essentials does) you should be able to use the modifyVars option.

Or alternatively when you normally compile main.less you can try to compile a new file (dynamically edit / generated):

@import "main.less"
@color: red;
Bass Jobsen
  • 48,736
  • 16
  • 143
  • 224