Steve
Steve

Reputation: 1046

Combine css files

I'm using Silverstripe 3.0

I tried to combine all my css files into one file:

$themeFolder = 'themes/' . SSViewer::current_theme() . '';

$cssFiles = array(
    $themeFolder . '/css/reset.css',
    $themeFolder . '/css/typography.css',
    $themeFolder . '/css/jquery.fancybox.css',
    $themeFolder . '/css/form.css'        
);

array_walk($cssFiles,'Requirements::css');
Requirements::combine_files($themePath . 'css/core.css',$cssFiles);
Requirements::set_combined_files_folder('.');
Requirements::process_combined_files();

Unfortunately instead of having one file core.css which combines the others, I have still 4 css files. It seems that silverstripe has no permission to write my css files?

Any idea what is going wrong? Thank you

Upvotes: 2

Views: 740

Answers (1)

Turnerj
Turnerj

Reputation: 4278

(Even though this is answered in the comments, adding a real answer so this question doesn't appear in the unanswered list on SO)

@ajshort is spot on for why this would happen:

Are you in development mode? If so, SilverStripe will not combine files for ease of development.

Technical Description

In the Requirements_Backend class which does the heavy lifting for the Requirements class, there is a line of code (SS 3.0 and SS 3.1) during the processing of combined files that affects whether it will combine or not.

Taken straight from the API docs:

if((Director::isDev() && !$runningTest && !isset($_REQUEST['combine'])) || !$this->combined_files_enabled) {
    return;
}

Basically if you are in dev-mode and SaphireTest is not running and that there is not a GET or POST variable set called "combine".

That means if you include a query parameter called "combine" (?combine=false), it will still combine the files while you are in dev-mode.

Upvotes: 2

Related Questions