-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Is it possible to lookup for variable that doesn't exist? #3444
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
Comments
@theexplay The short answer is that no, there's no current way to do this in exactly the way you mention. One workaround, though, would be to specify all the var names in a file loaded before the optional definitions, and set those values to something you would check later. In other words: // default values
@icon__glyph_about_20__1: false;
@icon__glyph_about_20__2: false;
@icon__glyph_about_32__1: false;
@icon__glyph_about_32__2: false;
// generated values
@icon__glyph_about_20__1: '\E00C';
@icon__glyph_about_32__1: '\E00D';
@icon__glyph_about_32__2: '\E00E';
// common mixin for icons
.nbl-icon__use(@iconName) {
@icon1: ~'icon__glyph_@{iconName}__1'; // always exists
@icon2: ~'icon__glyph_@{iconName}__2'; // sometimes doesn't exist
&::before {
content: @@icon1;
}
& when not (@@icon2 = false) {
&::after {
content: @@icon2;
}
}
}
.test {
.nbl-icon__use(about_20);
} |
By the way, you can shorten the &::after when (@@icon2) {
content: @@icon2;
} |
I'll try to do as you suggested, but maybe this will also be a rather difficult option for me. Since I use data from the system design, I don’t really want to add another “middleware”. Thank you so much for such a quick reply! |
Just in case (and unless I'm missing a corresponding change in v3.x) the example above is a bit misleading since Less has non-mainstream @foo: none; // or anything you like
... when not (@foo = none) or @foo: boo; // anything but string
... when (isstring(@foo)) etc. ref: #1400 |
Oh, shoot. That's a good catch. This is one of those cases where doing a lot of Less refactoring has tricked my brain towards what Less will do vs. what Less currently does do. It should be: & when not (@@icon2 = false) {
&::after {
content: @@icon2;
}
} You're right that Less currently expects something close to |
Hello!
Is it possible to lookup for variables that doesn't exist? I have a list of generated variables for every icon glyph. Some icons consist from two 2 glyphs (need for
::before
+::after
for 2 colors icon). I want to pass base icon name to mixin and get correct output, but i get an error of looking@@icon2
, and it doesn't matter if i usewhen
orif
. Also tried to use mixin guards, but no changes.Some code:
Example of error:

Message: variable @icon__glyph_about_20__2 is undefined in file ...
P.S. Unfortunately i can't generate list of vars with
null
's.P.S.S. sry for my eng, hope u understand me
The text was updated successfully, but these errors were encountered: