7

How do I import .less files with string interpolation in the pathstring.

@folder: "LessFiles";

I tried this

@import "@{folder}/file.less";

Error:
File Not Found. 
HTTP GET Url is "%7Bfolder%7D/file.less" 

and this:

@import formatString("{0}/file.less",@folder);

Error:
Server throws System.NullReferenceException

and this:

@path: "@{folder}/file.less";

@import @path;

Error:
directive block with unrecognised format on line 16 in file 'test.less':
 [15]: 
 [16]: @import @path;
       --------^
 [17]: 

Any tips how to solve this?

Thanks!

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
smunar
  • 195
  • 3
  • 10
  • it is an upcoming feature in less.js and dotless but requires a lot of work to implement. – Luke Page Sep 11 '12 at 12:44
  • Really? But it´s working for css attributes very well, e.g. its possible to define [background-image: url('@{image-folder}/loading-image.gif');], I´m wondering whats the difficult part. – smunar Sep 11 '12 at 13:39
  • 2
    imports are done at parsing and interpolation at evaluation.. need to get parsing to be allowed during evaluation. – Luke Page Sep 16 '12 at 12:57
  • issue on github (thanks to Luke for working on it): https://github.com/dotless/dotless/issues/249 – smunar Sep 20 '12 at 10:38

1 Answers1

1

As of Less 1.4.0 variable interpolation is possible with @imports

Example

@bacon: "../bacon";

@import @{bacon}/smokey.less; 

More information can be found here - Less Language Features import statements

Colin Bacon
  • 15,436
  • 7
  • 52
  • 72