LESS mix variable into attribute name in an attrib

2019-08-05 02:00发布

问题:

How can I implement the following syntax correctly?

.jacket(@classname, @attrname, @value) {
    .class-prefix-@{classname}[some-prefix-@{attrname}~="@{value}"] {
        //                                 ^Error From Here
        // Attributes
    }
}

lessc shows that there is an SyntaxError: expected ']' got '@'

回答1:

It seems like a bug actually, this workaround should do the trick:

.jacket(@classname, @attrname, @value) {
    @attr: ~'some-prefix-@{attrname}';
    .class-prefix-@{classname}[@{attr}~="@{value}"] {
        // ...
    }
}


标签: css less