Search code examples
csslesslessphp

Less override variable just for one country (language)


The context of my problem : I have a website multi-language ( 20 ), I use less css. All stylesheets are common, except one for every country called to the end.

I have a file com.base.less which has a variable of font. Every stylesheet calls this file to use the variables which it contains.

My question, for a country I must change the font, thus to re-declare the variable only for this country. How can I proceed?

Because if I re-celare my variable in my file of country, that this being called to the end it isn't written again.

I use lessPhp, and I see ModifyVars but I don't know if it's good method ? (when I test he doesn't work)

Thank you


Solution

  • Yes, as the docs tell you "You can use the ModifyVars() method to customize your CSS if you have variables stored in PHP associative arrays".

    Less uses the last declaration wins rule for variables, so the last re-declare value of variable at the end of your code will be used everywhere in your code.

    I use lessPhp, and I see ModifyVars but I don't know if it's good method ? (when I test he doesn't work)

    Make sure that you call ModifyVars() before getCss() and call both on the same instance of Less_Parser.