0

My less file is dependent on many variables such as:

@fontRegular:       "AvenirNextCondensed-Regular";

And classes make use of those variables, as follows:

.thisClass {
   font-family: @fontRegular;
}

As you can expect, I need to retheme on-the-fly.

The theme itself redefines those variable, as follows):

@fontRegular:       "HelveticaNeue";

How can I require less to reparse everything (I mean my less file) and how can I change the variables first?

5
  • In what javascript environment? Node? Browser? Commented Jun 24, 2014 at 7:38
  • Browser environment (client side) @seven-phases-max Commented Jun 24, 2014 at 15:59
  • See modifyVars and related topics here. Commented Jun 24, 2014 at 16:08
  • Thank you, modifyVars was exactly what I was looking for, you made my day @seven-phases-max. Create an answer and I accept it. Commented Jun 24, 2014 at 17:41
  • Sorry, I'm lazy. Feel free to answer yourself and accept your own :) Commented Jun 24, 2014 at 19:27

1 Answer 1

1

Simply invoke less from you javascript (in this case, it's from my controller) as follows:

    less.modifyVars(
        $scope.config.fontStyleHelveticaNeue? {
            '@fontRegular':     "HelveticaNeue",
            '@fontUltraLight':  "HelveticaNeue-UltraLight",
            '@fontDemiBold':    "HelveticaNeue-CondensedBold"
        }
        : {
            '@fontRegular':     "AvenirNextCondensed-Regular",
            '@fontUltraLight':  "AvenirNextCondensed-UltraLight",
            '@fontDemiBold':    "AvenirNextCondensed-DemiBold"
        }
    );

Where on the example above, all @-prefixed words are my less variables I update (actually, there are two set there). Less will rebuild all the css automatically.

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

Comments

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.