Actions

Difference between revisions of "JDocument/addStyleSheet"

From Joomla! Documentation

m (Missed & in code sample.)
(Replaced JS function: MIME, example section + added real example)
Line 18: Line 18:
 
|string
 
|string
 
|MIME type of script.
 
|MIME type of script.
|'text/javascript'
+
|'text/css'
 
|-
 
|-
 
|$media
 
|$media
Line 31: Line 31:
 
|}
 
|}
 
===Example===
 
===Example===
To add a link to some JavaScript code at a specific URL, you could use:
+
To add a link to some style sheet at a specific URL, you could use:
 
<source lang="php">
 
<source lang="php">
 
$doc =& JFactory::getDocument();
 
$doc =& JFactory::getDocument();
$doc->addScript( “http://www.example.com/js/myscript.js” );
+
$doc->addStyleSheet( “http://www.example.com/css/mystylesheet.css” );
 
</source>
 
</source>
 +
 +
Example code will produce following link:
 +
<source lang="javascript">
 +
<link rel="stylesheet" href="http://www.example.com/css/mystylesheet.css" type="text/css" />
 +
</source>
 +
 
===See also===
 
===See also===
 
* [http://api.joomla.org/Joomla-Framework/Document/JDocument.html#addStyleSheet JDocument->addStyleSheet on api.joomla.org]
 
* [http://api.joomla.org/Joomla-Framework/Document/JDocument.html#addStyleSheet JDocument->addStyleSheet on api.joomla.org]

Revision as of 11:51, 10 November 2008

Adds the definition of a linked external stylesheet to the document. Duplicates are ignored.

Syntax

void addStyleSheet( $url, $type, $media, $attribs )

where:

Argument Data type Description Default
$url string URL of stylesheet.
$type string MIME type of script. 'text/css'
$media string Media type that the stylesheet applies to. null
$attribs array Array of attributes.

Example

To add a link to some style sheet at a specific URL, you could use:

$doc =& JFactory::getDocument();
$doc->addStyleSheet( “http://www.example.com/css/mystylesheet.css” );

Example code will produce following link:

<link rel="stylesheet" href="http://www.example.com/css/mystylesheet.css" type="text/css" />

See also