6

I want to define a variable, which could be empty in some cases @prefix: "";

and to use it like this src: url("@{prefix}/path/to/something");

the problem is that it compiles into src: url("""/path/to/something");

How to define an empty string variable, that can be compiled in src: url("/path/to/something");

Update: Issue closed https://github.com/cloudhead/less.js/issues/532

2 Answers 2

18

Just found a way to do this... escape an empty string @prefix: ~'';

I ran into this with the box-shadow inset option that will often remain empty.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure this is possible in less. You could make a mixin function which returns the path with the prefix prepended to it. This would be useful if you want to change the prefix once in awhile and only have to do it in one place.

.prefixRed(@path: @defaultpath) {
    background: transparent url("red/@{path}");
}
.prefixBlue(@path: @defaultpath) {
    background: transparent url("blue/@{path}");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.