Actions

API16

JHtml/stylesheet

From Joomla! Documentation

< API16:JHtml
Revision as of 21:55, 13 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Write a <link rel="stylesheet" style="text/css"> element

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

static stylesheet($file, $attribs=array(), $relative=false, $path_only=false)
Parameter Name Default Value Description
$file path to file
$attribs array() attributes to be added to the stylesheet
$relative false path to file is relative to /media folder
$path_only false return the path to the file only

Defined in

libraries/joomla/html/html.php

Importing

jimport( 'joomla.html.html' );

Source Body

public static function stylesheet($file, $attribs = array(), $relative = false, $path_only = false)
{
        if (is_array($attribs)) {
                $attribs = JArrayHelper::toString($attribs);
        }
 
        if($relative)
        {
                $app = JFactory::getApplication();
                $cur_template = $app->getTemplate();
                if (file_exists(JPATH_THEMES .'/'. $cur_template .'/css/'. $file)) {
                        $file = JURI::base(true).'/templates/'. $cur_template .'/css/'. $file;
                } else {
                        list($extension, $file) = explode('/', $file, 2);
                        if (strpos($file, '/')) {
                                // Try to deal with plugins group
                                list($element, $file) = explode('/', $file, 2);
                                if (file_exists(JPATH_ROOT .'/media/'.$extension.'/'.$element.'/css/'.$file)) {
                                        $file = JURI::root(true).'/media/'.$extension.'/'.$element.'/css/'.$file;
                                } else {
                                        $file = JURI::root(true).'/media/'.$extension.'/css/'.$element.'/'.$file;
                                }
                        }
                        else {
                                $file = JURI::root(true).'/media/'.$extension.'/css/'.$file;
                        }
                }
                if($path_only)
                {
                        return $file;
                }
        } elseif (strpos($file, 'http') !== 0) {
                $file = JURI::root(true).'/'.$file;
        }
 
        $document = &JFactory::getDocument();
        $document->addStylesheet($file, 'text/css', null, $attribs);
        return;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />