CSS getting stuck in cache
Permalink
Hi
My CSS is getting stuck in /files/cache/css/fruitful/iGotStyle.css and the file isn't being updated as a result.
This is the code I'm using
<?php print $html->css($view->getStyleSheet('iGotStyle.less'));?>
Could someone tell me how to get over this please?
Many thanks in advance
My CSS is getting stuck in /files/cache/css/fruitful/iGotStyle.css and the file isn't being updated as a result.
This is the code I'm using
<?php print $html->css($view->getStyleSheet('iGotStyle.less'));?>
Could someone tell me how to get over this please?
Many thanks in advance
You'll likely need to clear the cache under Optimization in the Settings menu.
Have tried this but it's still calling to the cache folder
Assuming you're using Fruitful?
I had some memory issues with the LESS files. I got around it by turning off caching (during development), made the edits in the LESS file, cleared cache, refreshed page. Turn on caching when finished.
LESS is still a bit out of my grasp in practice so it's still a bit of voodoo to me. I think, and I welcome any corrections here, that the LESS file is processed into the cache and so that's where the theme/C5 will read it from.
I had some memory issues with the LESS files. I got around it by turning off caching (during development), made the edits in the LESS file, cleared cache, refreshed page. Turn on caching when finished.
LESS is still a bit out of my grasp in practice so it's still a bit of voodoo to me. I think, and I welcome any corrections here, that the LESS file is processed into the cache and so that's where the theme/C5 will read it from.
Thanks for this have tried this but still not updating the CSS - any other ideas??
I've come across many threads which mention exactly the same problem, so I came up with a solution for everyone. Please bear in mind this solution is for the latest version of Concrete5 (v5.7.5.9)
Step 1:
Copy the /concrete/src/Page/Theme/Theme.php to /application/src/Page/Theme (create the /src directory within the /application directory)
Step 2:
Open /application/src/Page/Theme/Theme.php and replace everything with the following:
namespace Application\Src\Page\Theme;
use Config;
use Environment;
class Theme extends \Concrete\Core\Page\Theme\Theme
{
public function getStylesheetObject($stylesheet)
{
$env = Environment::get();
$output = $this->getStylesheetCachePath().'/'.DIRNAME_CSS.'/'.$this->getThemeHandle();
$relative = $this->getStylesheetCacheRelativePath().'/'.DIRNAME_CSS.'/'.$this->getThemeHandle();
$r = $env->getRecord(
DIRNAME_THEMES.'/'.$this->getThemeHandle().'/'.DIRNAME_CSS.'/'.$stylesheet,
$this->getPackageHandle()
);
$stylesheet = new \Application\Src\StyleCustomizer\Stylesheet($stylesheet, $r->file, $r->url, $output, $relative);
return $stylesheet;
}
public function getStylesheet($stylesheet)
{
$stylesheet = $this->getStylesheetObject($stylesheet);
$styleValues = $this->getThemeCustomStyleObjectValues();
if (!is_null($styleValues)) {
$stylesheet->setValueList($styleValues);
}
if (!$this->isThemePreviewRequest()) {
if (!$stylesheet->outputFileExists() || !Config::get('concrete.cache.theme_css')) {
$stylesheet->output();
} else {
$outputPathLess = str_replace( '.css', '.less', $stylesheet->getOutputPath() );
if (filesize($stylesheet->getSourcePath()) != filesize($outputPathLess) ) {
$stylesheet->output();
}
}
}
$path = $stylesheet->getOutputRelativePath();
if ($this->isThemePreviewRequest()) {
$path .= '?ts='.time();
}
return $path;
}
}
AND... replace \Concrete\Core\Page\Theme\Theme with \Application\Src\Page\Theme\Theme, so the theme classes extends from our version of the core theme class.
Step 3:
Copy across the /concrete/src/StyleCustomizer/Stylesheet.php to /application/src/StyleCustomizer
Step 4:
Modify the Stylesheet class file output function with the following:
public function output()
{
$css = $this->getCss();
$sourceLess = file_get_contents($this->file);
$outputPathLess = $this->outputDirectory . '/' . $this->stylesheet;
$path = dirname($this->getOutputPath());
if (!file_exists($path)) {
@mkdir($path, Config::get('concrete.filesystem.permissions.directory'), true);
}
file_put_contents($this->getOutputPath(), $css);
file_put_contents($outputPathLess, $sourceLess);
}
AND... append the following function anywhere within the Stylesheet class
public function getSourcePath()
{
return $this->file;
}
Step 5:
Enjoy!
Step 1:
Copy the /concrete/src/Page/Theme/Theme.php to /application/src/Page/Theme (create the /src directory within the /application directory)
Step 2:
Open /application/src/Page/Theme/Theme.php and replace everything with the following:
namespace Application\Src\Page\Theme;
use Config;
use Environment;
class Theme extends \Concrete\Core\Page\Theme\Theme
{
public function getStylesheetObject($stylesheet)
{
$env = Environment::get();
$output = $this->getStylesheetCachePath().'/'.DIRNAME_CSS.'/'.$this->getThemeHandle();
$relative = $this->getStylesheetCacheRelativePath().'/'.DIRNAME_CSS.'/'.$this->getThemeHandle();
$r = $env->getRecord(
DIRNAME_THEMES.'/'.$this->getThemeHandle().'/'.DIRNAME_CSS.'/'.$stylesheet,
$this->getPackageHandle()
);
$stylesheet = new \Application\Src\StyleCustomizer\Stylesheet($stylesheet, $r->file, $r->url, $output, $relative);
return $stylesheet;
}
public function getStylesheet($stylesheet)
{
$stylesheet = $this->getStylesheetObject($stylesheet);
$styleValues = $this->getThemeCustomStyleObjectValues();
if (!is_null($styleValues)) {
$stylesheet->setValueList($styleValues);
}
if (!$this->isThemePreviewRequest()) {
if (!$stylesheet->outputFileExists() || !Config::get('concrete.cache.theme_css')) {
$stylesheet->output();
} else {
$outputPathLess = str_replace( '.css', '.less', $stylesheet->getOutputPath() );
if (filesize($stylesheet->getSourcePath()) != filesize($outputPathLess) ) {
$stylesheet->output();
}
}
}
$path = $stylesheet->getOutputRelativePath();
if ($this->isThemePreviewRequest()) {
$path .= '?ts='.time();
}
return $path;
}
}
AND... replace \Concrete\Core\Page\Theme\Theme with \Application\Src\Page\Theme\Theme, so the theme classes extends from our version of the core theme class.
Step 3:
Copy across the /concrete/src/StyleCustomizer/Stylesheet.php to /application/src/StyleCustomizer
Step 4:
Modify the Stylesheet class file output function with the following:
public function output()
{
$css = $this->getCss();
$sourceLess = file_get_contents($this->file);
$outputPathLess = $this->outputDirectory . '/' . $this->stylesheet;
$path = dirname($this->getOutputPath());
if (!file_exists($path)) {
@mkdir($path, Config::get('concrete.filesystem.permissions.directory'), true);
}
file_put_contents($this->getOutputPath(), $css);
file_put_contents($outputPathLess, $sourceLess);
}
AND... append the following function anywhere within the Stylesheet class
public function getSourcePath()
{
return $this->file;
}
Step 5:
Enjoy!