【问题标题】:How do I import .less files with string interpolation in the pathstring?如何在路径字符串中导入带有字符串插值的 .less 文件?
【发布时间】:2019-02-05 19:10:25
【问题描述】:

如何在路径字符串中导入带有字符串插值的 .less 文件。

@folder: "LessFiles";

我试过了

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

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

还有这个:

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

Error:
Server throws System.NullReferenceException

还有这个:

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

@import @path;

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

任何提示如何解决这个问题?

谢谢!

【问题讨论】:

  • 这是 less.js 和 dotless 中即将推出的功能,但需要大量工作才能实现。
  • 真的吗?但它非常适用于 css 属性,例如可以定义 [background-image: url('@{image-folder}/loading-image.gif');],我想知道困难的部分是什么。
  • 导入是在解析和评估时完成的。需要在评估期间允许解析。
  • github 上的问题(感谢 Luke 的工作):github.com/dotless/dotless/issues/249

标签: string import less string-interpolation dotless


【解决方案1】:

从 Less 1.4.0 开始,可以使用 @imports 进行变量插值

示例

@bacon: "../bacon";

@import @{bacon}/smokey.less; 

更多信息可以在这里找到 - Less Language Features import statements

【讨论】:

    猜你喜欢
    • 2015-10-26
    • 2015-06-19
    • 2020-03-30
    • 1970-01-01
    • 1970-01-01
    • 2014-08-24
    • 2018-05-02
    • 1970-01-01
    • 2015-12-14
    相关资源
    最近更新 更多