Not signed in (Sign In)
 
Sep 13th 2007 edited
 
Duplicate values in Head::Scripts and Head::StyleSheets should be removed before render, using array_unique().
 
Sep 13th 2007 edited
 
e.g.:
function Render() {
// First sort the stylesheets by key
if (is_array($this->StyleSheets)) {
ksort($this->StyleSheets);

// Remove duplicate values
// Can't use directly array_unique (only works on strings)
foreach ($this->StyleSheets as $Key => $Value) {
$this->StyleSheets[$Key] = serialize($Value);
}
$this->StyleSheets = array_unique($this->StyleSheets);
foreach ($this->StyleSheets as $Key => $Value) {
$this->StyleSheets[$Key] = unserialize($Value);
}
}
if (is_array($this->Scripts)) {
// Remove duplicate values
$this->Scripts = array_unique($this->Scripts);
}
$this->CallDelegate('PreRender');
include(ThemeFilePath($this->Context->Configuration, 'head.php'));
$this->CallDelegate('PostRender');
}


Array unique only work with string value.
To remove them in $this->StyleSheets, we would have serialize all the value first.
 
Sep 17th 2007
 
Wouldn't it make more sense to *not* add them to the collection if they are already there?

Something like...

function AddScript($ScriptLocation, $ScriptRoot = '~') {
if (!is_array($this->Scripts)) $this->Scripts = array();
if ($ScriptRoot == '~') $ScriptRoot = $this->Context->Configuration['WEB_ROOT'];
$ScriptPath = $ScriptLocation;
if ($ScriptRoot != '') $ScriptPath = ConcatenatePath($ScriptRoot, $ScriptLocation);
if (!in_array($ScriptPath, $this->Scripts)) $this->Scripts[] = $ScriptPath;
}
 
Sep 17th 2007
 
It does. It's added for script.

I didn't change the AddStyleSheet(). Duplicate style sheets won't happen that often (that could since there are css frameworks out there and js framework can have style sheets) and since they cascade not adding a style sheet could change the style of a page, I don't know what it should do (not add? or remove the previous one?).

Issue information

  • 4
  • Dinoboff

    Dinoboff

    Bug Tracker

  • Resolved
  • Low
  • Feature

Vanilla 1.1.5 is a product of Lussumo. More Information: Documentation, Community Support.