9

If I am going to import multiple files from the same directory, I'd like to reuse the directory path (assuming the file with the import statements isn't in the same directory as the import targets). So far I've tried this:

@directoryPath: "../modules/core/less/";

@import @directoryPath + "file.less";
@import (@directoryPath + "file.less");
@import @{directoryPath}"file.less";
@import "@{directoryPath}file.less";

@filePath: @directoryPath + "file.less"; //I have verified this produces the proper string

@import @filePath;
@import @{filePath};

None of the 6 import statements work. Some of them work in the

source: url(/*LESS variables*/);

declaration, but don't work the same way in the @import statement. Any ideas on what will work?

Tahsis Claus
  • 1,879
  • 1
  • 15
  • 27
  • http://stackoverflow.com/questions/10676628/less-css-import-path-from-variable – floor Mar 27 '15 at 02:24
  • Is it possible to make grunt insert the filenames before running the lessc command? – Tahsis Claus Mar 27 '15 at 02:26
  • This one `@import "@{directoryPath}file.less";` is correct actually. But it looks like you're using `lessphp` (because in standard Less `@directoryPath + "file.less";` is an invalid statement) and it simply does not support string interpolation for imports. – seven-phases-max Mar 27 '15 at 02:41
  • I believe both statements you listed errored, but I'll check again. – Tahsis Claus Mar 27 '15 at 02:51
  • Your first statement worked. If you turn it into an answer I will mark it as correct. – Tahsis Claus Mar 27 '15 at 14:52
  • Since http://stackoverflow.com/questions/10676628/ was asked before this feature is actually implemented and there it may be not so simple to notice what is the correct syntax, I guess I'll write a new A here. – seven-phases-max Mar 28 '15 at 23:12

1 Answers1

13

See Variables > Variable Interpolation > Import statements in the documentation.

The proper syntax is:

@path: "../modules/core/less/";

@import "@{path}file.less";
seven-phases-max
  • 11,765
  • 1
  • 45
  • 57