Skip to content

what about dynamic variable names? #2983

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
markentingh opened this issue Nov 6, 2016 · 2 comments
Closed

what about dynamic variable names? #2983

markentingh opened this issue Nov 6, 2016 · 2 comments

Comments

@markentingh
Copy link

markentingh commented Nov 6, 2016

for example:

@prefix:"my";
@suffix:"color";

.color(@name, @color){
    @tmp:~"@{prefix}-@{name}-@{suffix}";
    @{tmp}:@color;
}

.color(~"red",#cc0000);

body{background:@my-red-color;}

is something like this possible, where I define a custom variable name "@my-red-color" via a function, then use that custom variable as a property value?

@seven-phases-max
Copy link
Member

seven-phases-max commented Nov 7, 2016

For the feature-request see #2702 (there were also earlier threads but so far no good use-cases were suggested). From your example it seems like you're just looking for some sort of namespacing, though exact example/pattern would vastly depend on your actual use-case (after all it's not so easy to imagine how .color(~"red", #cc0000); could be better than @my-red-color: #cc0000; and when actually one need to change those prefixes and suffixes w/o actually changing background: @my-red-color;).

So here just a generic minimal namespacing example:

.theme(my) {
    @red:  #c00;
    @blue: #00c;
}

.theme(your) {
    @red:  #933;
    @blue: #339;
}

body {
    .theme(my);
    color:      @red;
    background: @blue;
}

p {
    .theme(your);
    background: @blue;
    // etc.      
}

// etc.

(Related: less/less-meta#12).

@seven-phases-max
Copy link
Member

seven-phases-max commented Nov 7, 2016

Closing as duplicate of #2702 (I treat this as an FR since the issue tracker is usually not for "How-To"/"Is it possible" type of questions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants