It will only return Unique References of CSS Declarations to layout.tpl.
This requires no Database access.
Complete instructions and samples are included in the ZIP attached.
This is the basic Idea of how it works.
library/template/cssdefinition.php
Code: Select all
<?php
Class CssDefinition {
var $CssDef = array();
function setcss($CssStyle){
if (array_search($CssStyle,$this->CssDef)===false){
$this->CssDef[]=$CssStyle;
}
}
}
?>
Code: Select all
function createCssDefinition() { // New CSS
require_once(DIR_LIBRARY . 'template/cssdefinition.php');
return new CssDefinition($this);
}
the tpl file to define your css file, replacing category.css with whatever your css file is.
Code: Select all
<?php
$css="catalog/template/" . $this->directory . "/css/category.css";
if (!file_exists($css)) {
$css="catalog/template/default/css/[color=blue]category.css[/color]";
}
$cssstyle->setcss("<link rel=\"stylesheet\" type=\"text/css\" href=\"".$css."\">");
?>
In (ADD the RED lines)
Code: Select all
function fetch() {
$config =& $this->locator->get('config');
$database =& $this->locator->get('database');
$language =& $this->locator->get('language');
$url =& $this->locator->get('url');
$request =& $this->locator->get('request');
[color=red]$template =& $this->locator->get('template'); // New CSS Required in all Controller files if not present
$cssstyle =& $this->locator->get('cssdefinition'); // New CSS Required[/color]
if ($config->get('category_status'))
Code: Select all
$view->set('categories', $new_category_data);
[color=red] $view->set('cssstyle',$cssstyle); // New CSS
$template->set('cssstyle',$cssstyle); // New CSS[/color]
return $view->fetch('module/category.tpl');
CATALOG/TEMPLATE/YOURTEMPLATE/layout.tpl add the following code under your default.css declaration
Code: Select all
<?php // New CSS Generator
if (isset($cssstyle->CssDef)){
foreach ($cssstyle->CssDef as $pagecss){
echo $pagecss."\n";
}
}
?>
-EDIT BY Qphoria: Cleaned up code using code tags. Makes it easier to read-