Skip to content

Support || operator for variables #318

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

Closed
wants to merge 4 commits into from
Closed

Conversation

jamie-pate
Copy link

Adds || (boolean or) operator

allows conditional overriding of variable values

@someVariable:red;
@include "otherfile.less"
=================contents of "otherfile.less"=========
@someVariable : @someVariable || green;

jamie-pate and others added 4 commits July 12, 2011 17:12
allows conditional overriding of variable values

@someVariable:red;
@include "otherfile"
=================contents of "otherfile"=========
@someVariable:@someVariable||green;
@jamie-pate jamie-pate closed this Jul 13, 2011
@jamie-pate jamie-pate reopened this Jul 13, 2011
@lukeapage
Copy link
Member

I am wondering whether this is best suited as an an operator or a function?

also your pull request includes 2 commits from a different release

@MatthewDL @Synchro are you happy for me to close and add a feature request for a function or do you like this?

@matthew-dean
Copy link
Member

What's the use case here? To assign a value only if another LESS file hasn't been imported?

Note also that, in this example, @someVariable are both executed in the same scope, so it can't be redefined in this way and refer to itself. It's clear that the author is interpreting LESS more like JavaScript than CSS. So, overall, this has a number of problems which don't feel sufficiently addressed.

@Synchro
Copy link
Member

Synchro commented Dec 13, 2012

I don't think it's especially useful (why not just set the colour right?), but I think it's another fudge for the lack of conditional structures.

@matthew-dean
Copy link
Member

A mixin guard can actually do this, I believe.

@lukeapage
Copy link
Member

Yes a guard can do this.. the use case for me is user set theme variables..
if you want to keep one definition of a color and then fallback on a
default.. using mixin guards ends up with a lot of code just to set a
variable.

Yes, its needed because less doesn't have control structures.. having a
function or operator is a declarative way of keeping the same functionality.

But I think the operator is messy.. I prefer a function.

@lukeapage
Copy link
Member

closing as we all agree operator is not the way to go

@lukeapage lukeapage closed this Dec 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants