Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I think this is not possible, but I thought I ask in case there is a way. The idea is that I have a variable for path to web resource folder so that I only need to change 1 variable in case the path changes.

@root: "../img/";

@file: "test.css";

@url: @root@file;

.px{ background-image: url(@url); }

I get this

.px { background-image: url("../img/" "test.css"); }

instead of

.px { background-image: url("../img/test.css"); }

Any idea on how to achieve this?

share|improve this question

3 Answers

up vote 22 down vote accepted

Use String Interpolation to do this by changing:

@url: @root@file;

To:

@url: "@{root}@{file}";

Full code:

@root: "../img/";
@file: "test.css";

@url: "@{root}@{file}";

.px{ background-image: url(@url); }
share|improve this answer
2  
You can test that this full code works here: leafo.net/lessphp/#demo – Paulpro Apr 21 '12 at 5:23
Thanks for the answer! This is perfect. Now I can make sure that even if the context path changes, there won't be a refactoring nightmare. – juminoz Apr 21 '12 at 18:16
@juminoz No problem :) I'm glad I could help. – Paulpro Apr 21 '12 at 18:21
Thanks, i just came across the same problem and missed that in the docs. – David May 3 '12 at 18:24
No problem @David :) – Paulpro May 3 '12 at 19:09

Don't know if you're using less.js or lessphp (like in WP-Less plugin for WordPress) but with lessphp you can "unquote" strings with ~ : http://leafo.net/lessphp/docs/#string_unquoting

share|improve this answer

Using Drupal 7. I've used an ordinary plus mark and it's working:

@images_path+'bg.png'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.