5

While testing my web app, I'd like to be able to set the value of one of my LESS @variables using a simple dropdown. (To change the color scheme altogether).

I guess after setting the value, LESS has to reload/recompile the .less files with the new value?

Is there any simple way of accomplishing this? (I'm not running node.js)

The basic example would be something like:

styles.less
@base-color = `window.baseColor()`
2
  • What do you mean, you don't run node.js? Is your LESS-file compiled into CSS on the server-side? Commented Nov 28, 2011 at 15:36
  • No, I'm just including it like this: <link rel="stylesheet/less" type="text/css" href="styles.less"> <script src="less.js" type="text/javascript"></script> Commented Nov 28, 2011 at 20:18

1 Answer 1

6

I think you're doing it in a bit too complicated way ;)

Here's what I propose:

  1. Set a class on your body tag:

    <body class='theme_default'></body>
    
  2. In your .less file define your themes:

    body.theme_default { base_color: #fff; }
    body.theme_gray    { base_color: #ccc; }
    etc..
    
  3. Using jQuery (or just plain JS) change the class of the body tag upon dropdown state change.

That's how I'd do it (and replace the dropdown with some nice widget ;) Cheers

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh, that sounds much more reasonable :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.