从PHP创建LESS变量

I'm not sure if this is possible but I thought I'd throw out the question just incase.

I'm developing a WordPress theme and in the Theme Options I have an option for the user to change the accent colour.

I'm using LESS to compile my CSS and I have a vars.less file which is imported into my main styles.less file. Within my vars.less file I set up an @accent variable which is then applied to different areas of the site as well as used in conjunction with the darken/lighten functions within LESS.

This is all fine and works great when @accent is defined within LESS however I want to get the colour selected within the Theme Options and apply it to this LESS variable to be used.

Does anyone know of anyway I could do this or if it's even possible?

Thanks, Martin

You can do that if you use the serverside LESS compiler by generating a mixins file and using the a LESS engine to recompile your scripts.

If you are using the desktop LESS application you would not be able to do it. You could, however, use a conditional stylesheet for your colors and use PHP to determine which stylesheet to use and output a link to the stylesheet. The stylesheets would simply have to override the styles that have already been defined.

The main issue here is that LESS must be compiled before it is usable by a CSS engine. Generating CSS is fine since it is directly interpreted after being generated. LESS must be generated and then parsed and compiled by the LESS engine.