Actions

Difference between revisions of "JDocument/setMetaData"

From Joomla! Documentation

m (Added table formatting.)
m (Missed & in code sample. Changed double-quotes to single-quotes for some strings.)
Line 26: Line 26:
 
===Example 1===
 
===Example 1===
 
<source lang="php">
 
<source lang="php">
$doc = JFactory::getDocument();
+
$doc =& JFactory::getDocument();
$doc->setMetaData( “tag-name”, “tag-content” );
+
$doc->setMetaData( 'tag-name', 'tag-content' );
 
</source>
 
</source>
 
Metadata is rendered differently depending on the document type.  For HTML documents a meta tag is produced in the <head> section of the document, so the above example will produce:
 
Metadata is rendered differently depending on the document type.  For HTML documents a meta tag is produced in the <head> section of the document, so the above example will produce:
Line 33: Line 33:
 
===Example 2===
 
===Example 2===
 
<source lang="php">
 
<source lang="php">
$doc = JFactory::getDocument();
+
$doc =& JFactory::getDocument();
$doc->setMetaData( “tag-name”, “tag-content”, true );
+
$doc->setMetaData( 'tag-name', 'tag-content', true );
 
</source>
 
</source>
 
Metadata is rendered differently depending on the document type.  For HTML documents a meta tag is produced in the <head> section of the document, so the above example will produce:
 
Metadata is rendered differently depending on the document type.  For HTML documents a meta tag is produced in the <head> section of the document, so the above example will produce:

Revision as of 03:57, 8 September 2008

Contents

Syntax

void setMetaData( $name, $content, $http-equiv )

where:

Argument Data type Description Default
$name string Name of meta data item. If $name is 'description' or 'generator' then the effect is the same as calling setDescription or setGenerator respectively.
$content string Content of meta data item.
$http-equiv Boolean True if meta data item is equivalent to an HTTP header field. false

Example 1

$doc =& JFactory::getDocument();
$doc->setMetaData( 'tag-name', 'tag-content' );

Metadata is rendered differently depending on the document type. For HTML documents a meta tag is produced in the <head> section of the document, so the above example will produce:

<meta name="tag-name" content="tag-content" />

Example 2

$doc =& JFactory::getDocument();
$doc->setMetaData( 'tag-name', 'tag-content', true );

Metadata is rendered differently depending on the document type. For HTML documents a meta tag is produced in the <head> section of the document, so the above example will produce:

<meta http-equiv="tag-name" content="tag-content" />

See also