Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 减少CSS&;Symfony-动态更新颜色方案_Php_Css_Symfony1_Symfony 1.4_Less - Fatal编程技术网

Php 减少CSS&;Symfony-动态更新颜色方案

Php 减少CSS&;Symfony-动态更新颜色方案,php,css,symfony1,symfony-1.4,less,Php,Css,Symfony1,Symfony 1.4,Less,我正在使用Symfony 1.4,使用较少的CSS预处理器时遇到了一些问题 假设我少了2个带有颜色特定变量的文件。它们被称为blue.less和red.less 这是: 蓝色。更少 @mainBorder: blue; @pulldownBackground: blue; @mainBorder: red; @pulldownBackground: red; 红色。较少 @mainBorder: blue; @pulldownBackground: blue; @mainBorder: r

我正在使用Symfony 1.4,使用较少的CSS预处理器时遇到了一些问题

假设我少了2个带有颜色特定变量的文件。它们被称为
blue.less
red.less

这是:

蓝色。更少

@mainBorder: blue;
@pulldownBackground: blue;
@mainBorder: red;
@pulldownBackground: red;
红色。较少

@mainBorder: blue;
@pulldownBackground: blue;
@mainBorder: red;
@pulldownBackground: red;
现在让我们假设我有一个布局.less文件,看起来像这样:

// Colored line under Nav
.main {
    border: 1px solid @mainBorder;
    .pullDown { background: @pullDownBackground; }
}
@import 'red.less';
如果我想使用其中一个颜色变量文件,我需要在布局的顶部声明它

// Colored line under Nav
.main {
    border: 1px solid @mainBorder;
    .pullDown { background: @pullDownBackground; }
}
@import 'red.less';
由于
@import
语句必须引用特定的文件,因此每当我想要更改配色方案时,如何能够动态地将
blue.less
传递给@import语句

是否有一种方法可以动态声明哪些特定于颜色的LESS文件将通过PHP和Symfony框架传递给该导入语句?


或者这个问题可以不用服务器端代码来解决吗?

我从来没有使用过Symphony,但是不管框架如何,这都会让您朝着正确的方向前进

首先,要创建LESS文件:

<?php
$color_scheme = "red"; // we're simplifying here for now, but this could be set via $_POST variable

/*
    it would probably be a good idea to check if the file exists first before we import it.
    see function: file_exists()
*/

$contents = "
@import '$color_scheme.less';
@import 'main_styles.less';
@import 'other_stuff.less';
";

file_put_contents("path/to/styles.less");
?>

如果Symphony插件为您进行编译而不需要使用exec/命令行,那么您可能会希望这样做。

我从来没有使用过Symphony,但无论框架如何,这都会让您朝着正确的方向前进

首先,要创建LESS文件:

<?php
$color_scheme = "red"; // we're simplifying here for now, but this could be set via $_POST variable

/*
    it would probably be a good idea to check if the file exists first before we import it.
    see function: file_exists()
*/

$contents = "
@import '$color_scheme.less';
@import 'main_styles.less';
@import 'other_stuff.less';
";

file_put_contents("path/to/styles.less");
?>

如果您的Symphony插件不需要使用exec/命令行就为您进行编译,那么您可能会希望这样做。

您是否考虑过通过PHP生成包含所有必要导入的较少文件,然后使用
exec
调用编译?我没有。我对PHP和Symfony相当陌生-目前通过sfLess插件处理的文件较少:。如果你能给我指点一个教程,让我开始学习你的建议,那就太好了。我还将查找PHP exec函数。您是否考虑过通过PHP生成包含所有必要导入的LESS文件,然后使用
exec
调用编译?我没有。我对PHP和Symfony相当陌生-目前通过sfLess插件处理的文件较少:。如果你能给我指点一个教程,让我开始学习你的建议,那就太好了。我还将查找PHP exec函数。