question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Variable Name Interpolation

See original GitHub issue

Currently 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:closed
  • Created 11 years ago
  • Reactions:2
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ngsilvermancommented, Feb 17, 2013

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.

0reactions
lukeapagecommented, Feb 13, 2014

closing due to inactivity

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found