Actions

Difference between revisions of "JDocument/setMetaData"

From Joomla! Documentation

(New page: ===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...)
 
m
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
Sets the value of a meta data item.
 
===Syntax===
 
===Syntax===
 
void setMetaData( $name, $content, $http-equiv )
 
void setMetaData( $name, $content, $http-equiv )
  
 
where:
 
where:
{|
+
{| class="wikitable"
 
!Argument
 
!Argument
 
!Data type
 
!Data type
Line 11: Line 12:
 
|$name
 
|$name
 
|string
 
|string
|Name of meta data item.  If $name is 'description' or 'generator' then the effect is the same as calling [[JDocument/setDescription|setDescription]] or [[JDocument/setGenerator|setGenerator]] respectively.
+
|Name of meta data item.  If $name is 'description' or 'generator' then the effect is the same as calling [[JDocument/setDescription|setDescription]] or [[JDocument/setGenerator|setGenerator]] respectively.  Meta data names are always folded to lowercase.
 
|
 
|
 
|-
 
|-
 
|$content
 
|$content
 
|string
 
|string
|Content of meta data item.
+
|Content of meta data item.  If there is already a meta data item with the same value of $name (case independent) then this value will replace it.
 
|
 
|
 
|-
 
|-
Line 26: Line 27:
 
===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 34:
 
===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:

Latest revision as of 08:53, 18 September 2008

Sets the value of a meta data item.

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. Meta data names are always folded to lowercase.
$content string Content of meta data item. If there is already a meta data item with the same value of $name (case independent) then this value will replace it.
$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