You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First let me explain what I want to do:
In php I have variables. i.e. $variable1 = 'red';
These variables I want to inject into the .less files for compilation: @button-top-top-color: $variable1
and in the CSS this would yield: @button-top-top-color: 'red';
I am having troubles with including variables into .less files that I can subsequently convert into .css by using assetic. I found the $vars array that is a parameter in the FileAsset class. I assume this parameter can be used to set additional variables that will be injected into assetic when dumping?
I used this code to test it, but I got the following error: Uncaught RuntimeException: The asset target path "_test_1" must contain the variable "{color}"
use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Filter\LessFilter;
// Play here
$variables = ['color'];
$fileAsset = new FileAsset(__DIR__.'/test.less', [new LessFilter()], null, null, $variables);
$fileAsset->setValues(['color' => '#000;']);
$css = new AssetCollection([
$fileAsset,
]);
print_r($css->dump());
Another idea to solve my problem would be to create a StringAsset that holds the .less content with its variables. This string I would have parsed beforehand. Would this work?
Kind regards, Jeroen
The text was updated successfully, but these errors were encountered:
I've also thought that $vars is something replaced in CSS before passing to filters, but after looking in the code this is somehow used to build final asset name. I wasn't able however find any examples of that.
I believe the variables you're setting are meant to be used for things like i18n to generate multiple asset names / urls. Each filter handles their variables differently. Pretty sure Less just inserts your variables at the end of the file on its own before parsing.
Hello everybody,
First let me explain what I want to do:
In php I have variables. i.e. $variable1 = 'red';
These variables I want to inject into the .less files for compilation: @button-top-top-color: $variable1
and in the CSS this would yield: @button-top-top-color: 'red';
I am having troubles with including variables into .less files that I can subsequently convert into .css by using assetic. I found the $vars array that is a parameter in the FileAsset class. I assume this parameter can be used to set additional variables that will be injected into assetic when dumping?
I used this code to test it, but I got the following error: Uncaught RuntimeException: The asset target path "_test_1" must contain the variable "{color}"
Another idea to solve my problem would be to create a StringAsset that holds the .less content with its variables. This string I would have parsed beforehand. Would this work?
Kind regards, Jeroen
The text was updated successfully, but these errors were encountered: