Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Set LESS-Variables in PHP #17

Closed
PhilJ opened this issue Mar 2, 2010 · 3 comments
Closed

Feature: Set LESS-Variables in PHP #17

PhilJ opened this issue Mar 2, 2010 · 3 comments

Comments

@PhilJ
Copy link

PhilJ commented Mar 2, 2010

Right at the moment the Compilation-Interface only allows to enter an input and an output filename. Wouldn't it be nice also to be able to pass parameters as an array, which can be used as variables in LESS? This could e.g. allow to easily include features like allowing a user to set a custom background-color or setting a custom font size. (Especially if you use the symfony-Plugin this would be a powerful feature)

At the moment you could only get such a behavior it you write a LESS-File which defines variables in PHP to the filesystem and then import that with your base file. But this is difficult to use, especially if you want to use several versions of a CSS-file at a time.

The easiest behavior for using this feature would be, that variables in the LESS-File would simply be overwritten. So - to not cause errors without PHP-parameters - default parameters can be set in the LESS-file which will be used, when no parameters are passed. Maybe you could also think of an "important!" for variable definition which would protect a variable of overwriting, but this would not be a necessary feature in my eyes.

PHP:

lessc::ccompile('input.less', 'out.css', array('background-color' => '#ddd'));

LESS:

@background-color: #fff;
body {
    background: @background-color; 
}

Compiled CSS:

body { background: #ddd; }
@xdissent
Copy link
Contributor

xdissent commented Mar 5, 2010

Handling multidimensional option arrays, dealing with variable name collisions, keeping options from breaking LESS in the context of mixin arguments - there are a lot of ins and outs to this issue. I'm not sure any one convention will ever meet all needs that are tempting you with this functionality, so it might just be best left up to PHP. I've accomplished passing PHP vars to the LESS compiler by parsing an options array and generating a LESS snippet with all of my LESS variable definitions, adding it to the front of my LESS file (read into PHP not through lessc::compile()) and then parsing through the LESS compiler. All this took was like 4 lines, and it's gone through a few iterations as my style generation scheme has developed. It's my opinion that an "official" way to do this will not fit all applications, and a lot of time will be wasted on trying to force it to do exactly that. It's just PHP and LESS after all, the sky is already the limit.

@leafo leafo closed this as completed Aug 18, 2012
@rahmansal
Copy link

This feature will be very nice, I am designing a website with base color and every other color is depending in this color with lighten() and darken() functions, It will be very powerful if i can give the user the ability to change the base color so he can change all other colors.

@leafo
Copy link
Owner

leafo commented Nov 29, 2012

http://leafo.net/lessphp/docs/#setting_variables_from_php

It works a little bit differently than described, it doesn't overwrite variables in the top scope. Something which I think I should change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants