有没有一种方法可以用PHP中的LESS编译器覆盖LESS变量? [英] Is there a way I can overwrite LESS variable with LESS compiler in PHP?

查看:86
本文介绍了有没有一种方法可以用PHP中的LESS编译器覆盖LESS变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用 lessphp 作为我的LESS编译器.我知道它提供了一种设置LESS变量的方法,但是有一种方法可以覆盖文件中设置的变量吗?

Currently I am using the lessphp as my LESS compiler. I know it provides a way to set the LESS variables, but is there a way to overwrite the variables set in the file?

例如,我有以下LESS文件:

For example, I have the following LESS file:

@theme-color: #000055;
h1 {
    color: @theme-color;
}
h2 {
    color: @theme-color * 1.3;
}
h3 {
    color: @theme-color * 1.5;
}

要在PHP中进行编译,

To compile it in PHP,

require"path/to/leafo/lessphp/lessc.inc.php";
$less = new lessc;
$less->setVariables(array(
    "theme-color" => "#000055"
));
$less->compileFile("basic/path/less/main.less", "basic/path//css/main.css");

它成功编译了文件,但是变量@ theme-color未被覆盖.有没有办法覆盖它?

It successfully compile the file but the variable @theme-color is not overwritten. Is there a way to overwrite it?

如果需要的话,我不介意使用其他编译器,但是它需要在服务器端使用,因为javascript编译器的速度太慢,并且会导致片刻没有CSS视图.

I don't mind using another compiler if necessary, but it needs to be server side as the javascript compiler is too slow and it creates a moment of no css view.

推荐答案

可能可以使用compile()代替compileFile();

$lesscode = file_get_contents("basic/path/less/main.less");
$lesscode .= "@themecolor: #000055;";

file_put_contents("basic/path//css/main.css", $less->compile($lesscode));

这篇关于有没有一种方法可以用PHP中的LESS编译器覆盖LESS变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆