Variable Name Interpolation
See original GitHub issueCurrently it’s possible to define variables with a variable name, like so:
@fnord: "I am fnord.";
@var: 'fnord';
content: @@var;
But not with a partially variable name, like so:
@fnord-string: "I am fnord.";
@var: 'fnord';
content: @@{var}-string;
This would be particularly useful for long parametric mixins that you’d like to behave slightly differently depending on a variable. For example:
@sans-serif: Arial, sans-serif;
@serif: Georgia, Times, serif;
@sans-serif-size: 16px;
@serif-size: 18px;
.typography(@font-family: sans-serif) {
font-family: @@font-family;
font-size: @@{font-family}-size;
}
Here our mixin isn’t very long so we could use pattern-matching instead, but I happen to be working on a mixin that does several baseline related calculations in which two values depend on the font being used. I don’t want to duplicate my mixins since I’d then have to update all of them if my calculations change.
Issue Analytics
- State:
- Created 11 years ago
- Reactions:2
- Comments:8 (6 by maintainers)
Top Results From Across the Web
SASS: interpolation in a name of variable - Krasimir Tsonev
The idea is to use a variable and construct another thing. However it is currently not possible to use interpolation in names of...
Read more >Sass interpolate a variable name to string - Stack Overflow
Since all the colors are formatted the same way, so I was hoping to write a mixin that takes the color's variable name,...
Read more >Simple variable interpolation
For example, we want to put some parameters as title in a plot. region = c(1, 2) value = 4 name = "name"...
Read more >Interpolation - Sass
Interpolation can be used almost anywhere in a Sass stylesheet to embed the result of a SassScript expression into a chunk of CSS....
Read more >Interpolating Variables Into a String - Real Python
In this lesson, you'll learn how to do variable interpolation with f-strings. With this feature, you can specify a variable name directly within...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fair point. I would argue that it’s reasonable to expect the
@@{var}-string
(or@{@{var}-string}
) syntax to work, and so when you need that functionality it’s the workaround that makes less more complicated.closing due to inactivity