Skip to content

Instantly share code, notes, and snippets.

Last active December 11, 2015 14:38
Show Gist options
  • Save phproberto/4615320 to your computer and use it in GitHub Desktop.
Save phproberto/4615320 to your computer and use it in GitHub Desktop.
Joomla! overridable asset loader

Joomla! overridable media asset loader

Asset loader based on @dongilbert asset loader ( )



Checks in this order (when called inside com_helloworld component):



ELHtml::asset('slide.js', 'mod_menu');

Checks in this order:



echo ELHtml::asset('search.png', 'mod_product_search', array('alt' => 'This is the alt text'));

Checks in this order:

defined('_JEXEC') or die;
class ELHtml extends JHtml
* Includes assets from media directory, looking in the
* template folder for a style override to include.
* @param string $filename Path to file.
* @param string $extension Current extension name. Will auto detect component name if null.
* @param array $attribs Extra attribs array
* @return mixed False if asset type is unsupported, nothing if a css or js file, and a string if an image
public static function asset($filename, $extension = null, $attribs = array())
if (is_null($extension))
$extension = array_pop(explode(DIRECTORY_SEPARATOR, JPATH_COMPONENT));
$toLoad = "$extension/$filename";
// Discover the asset type from the file name
$type = substr($filename, (strrpos($filename, '.') + 1));
switch (strtoupper($type))
case 'CSS':
return self::stylesheet($toLoad, $attribs, true, false);
case 'JS':
return self::script($toLoad, false, true);
case 'GIF':
case 'JPG':
case 'JPEG':
case 'PNG':
case 'BMP':
$alt = null;
if (isset($attribs['alt']))
$alt = $attribs['alt'];
return self::image($toLoad, $alt, $attribs, true);
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment