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

Indirect mixin calls / Mixin references #1338

Closed
glasserc opened this issue May 22, 2013 · 3 comments
Closed

Indirect mixin calls / Mixin references #1338

glasserc opened this issue May 22, 2013 · 3 comments

Comments

@glasserc
Copy link

Hi, I didn't see this in the open issues, so forgive me if it's called something else and I didn't see it..

At work we have a standard set of "colors" that we'd like to use in a lot of places. We'd like to define a mixin that we can use to repeat mixins for each color. An example of what we'd like:

.forManyColors(@mixinName) {
  .@{mixinName}("red");
  .@{mixinName}("blue");
  .@{mixinName}("green");
  .@{mixinName}("purple");
}

.background(@color){
  .background-@{color} {
    background-image: url("my-background-@{color}.jpg");
  }
}

.forManyColors("background");

Ideally, this should compile to:

.background-red {
    background-image: url("my-background-red.jpg");
} 
.background-blue {
    background-image: url("my-background-blue.jpg");
}
.background-green {
    background-image: url("my-background-green.jpg");
}
.background-purple {
    background-image: url("my-background-purple.jpg");
}

Unfortunately, it seems like interpolation in mixin names isn't possible. The code above gives me:

ParseError: Syntax Error on line 2 in /home/ethan/tmp/foo.less:2:18
1 .forManyNumbers(@mixinName) {
2   .@{mixinName}(4);
3   .@{mixinName}(3);

Here's another example:

.mixin-1 {
  width: 100px;
}

.mixin-2 {
  background-color: red;
}

@mixinNumber: 1;

.some-element {
  .mixin-@{mixinNumber};
}
@lukeapage
Copy link
Member

duplicate of #1196

@glasserc
Copy link
Author

Although the names are similar, #1196 is about defining mixins using an interpolated name, and this one is about invoking mixins using an interpolated name. I suspect that the two issues will be resolved in different ways. If you'd like to merge the two, I can comment with my problem on that issue, but I suspect it will just confuse the issue.

@seven-phases-max
Copy link
Member

Closing in favour of discussion at less/less-meta#16 (comment). Also renaming to match the nature of the proposal (it has very few to do with "interpolation" as such).

@seven-phases-max seven-phases-max changed the title interpolating mixin names Indirect mixin calls / Mixin references Nov 16, 2017
@less less deleted a comment from stale bot Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants