Actions

Difference between revisions of "JDocumentHTML/addHeadLink"

From Joomla! Documentation

m (Missed & in code sample.)
m
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Adds a link tag to the document head.
+
{{#lsth:Doxiki:JDocumentHTML/addHeadLink|Description}}
 
===Syntax===
 
===Syntax===
void addHeadLink( $href, $relation, $relType, $attribs )
+
addHeadLink( $href, $relation, $relType, $attribs )
  
 
where:
 
where:
Line 30: Line 30:
 
|
 
|
 
|}
 
|}
===Example===
+
 
To add a link for an RSS feed to the document, you could use:
+
===Returns===
<source lang="php">
+
{{#lsth:Doxiki:JDocumentHTML/addHeadLink|Returns}}
$doc =& JFactory::getDocument();
+
===Examples===
$href = '/joomla/index.php?format=feed&amp;type=rss';
+
<dpl>
$attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
+
category=JDocument
$doc->addHeadLink( $href, 'alternate', 'rel', $attribs );
+
category=addHeadLink
</source>
+
category=Code examples
When the document is rendered this will produce the following in the HTML <head> section:
+
include=*
<source lang="html4strict">
+
format=,\n====%TITLE%====\n,,
<link href="/joomla/index.php?format=feed&amp;type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
+
</dpl>
</source>
+
 
===See also===
 
===See also===
 
* [http://api.joomla.org/Joomla-Framework/Document/JDocumentHTML.html#addHeadLink JDocumentHTML->addHeadLink on api.joomla.org]
 
* [http://api.joomla.org/Joomla-Framework/Document/JDocumentHTML.html#addHeadLink JDocumentHTML->addHeadLink on api.joomla.org]
 +
 +
===Defined in===
 +
{{#lsth:Doxiki:JDocumentHTML/addHeadLink|Defined in}}
 +
 +
===Importing===
 +
{{#lsth:Doxiki:JDocumentHTML/addHeadLink|Importing}}
 +
===Source code {{JVer|1.6}}===
 +
{{#lsth:Doxiki:JDocumentHTML/addHeadLink|Source body}}
 +
 +
===CodeExamples Test===
 +
<CodeExamplesForm />
 +
 +
<dpl>
 +
category=JDocumentHTML
 +
category=addHeadLink
 +
category=MethodExample
 +
include=*
 +
format= ,,,
 +
</dpl>
 +
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocumentHTML]]</noinclude>
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocumentHTML]]</noinclude>

Latest revision as of 12:40, 3 January 2010

Doxiki:JDocumentHTML/addHeadLink

Contents

Syntax

addHeadLink( $href, $relation, $relType, $attribs )

where:

Argument Data type Description Default
$href strng URL of the linked resource.
$relation string Relation
$relType string Relation type. May be 'rel' indicating a forward relation, or 'rev' for a reverse relation. 'rel'
$attribs array Associative array of remaining attributes.

Returns

Doxiki:JDocumentHTML/addHeadLink

Examples

Adding a link for an RSS feed to the document

To add a link for an RSS feed to the document, you could use:

$doc =& JFactory::getDocument();
$href = '/joomla/index.php?format=feed&amp;type=rss'; 
$attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); 
$doc->addHeadLink( $href, 'alternate', 'rel', $attribs );

When the document is rendered this will produce the following in the HTML <head> section:

<link href="/joomla/index.php?format=feed&amp;type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />

Adding a link to a CSS file to the document

To add a link to a CSS file to the document, you could use:

$doc =& JFactory::getDocument();
$href = 'index.php/other/css/mycss.css'; 
$attribs = array('type' => 'text/css'); 
$doc->addHeadLink( $href, 'stylesheet', 'rel', $attribs );

When the document is rendered this will produce the following in the HTML <head> section:

<link href="/index.php/other/css/mycss.css" rel="stylesheet" type="text/css" />

This is an alternative to using JDocument->addStyleSheet.

See also

Defined in

Doxiki:JDocumentHTML/addHeadLink

Importing

Doxiki:JDocumentHTML/addHeadLink

Source code Joomla 1.6

Doxiki:JDocumentHTML/addHeadLink

CodeExamples Test

<CodeExamplesForm />


Test 1

This is a test of the CodeExamples extension.

Chris Davenport 12:44, 3 January 2010 (EST)