1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect3 id="zend.view.helpers.initial.headmeta">
4 <title>HeadMeta Helper</title>
7 The HTML <emphasis><meta></emphasis> element is used to provide meta
8 information about your HTML document -- typically keywords, document
9 character set, caching pragmas, etc. Meta tags may be either of the
10 'http-equiv' or 'name' types, must contain a 'content' attribute, and
11 can also have either of the 'lang' or 'scheme' modifier attributes.
15 The <classname>HeadMeta</classname> helper supports the following methods for
16 setting and adding meta tags:
22 <command>appendName($keyValue, $content, $conditionalName)</command>
28 <command>offsetSetName($index, $keyValue, $content, $conditionalName)</command>
34 <command>prependName($keyValue, $content, $conditionalName)</command>
40 <command>setName($keyValue, $content, $modifiers)</command>
46 <command>appendHttpEquiv($keyValue, $content, $conditionalHttpEquiv)</command>
52 <command>offsetSetHttpEquiv($index, $keyValue, $content,
53 $conditionalHttpEquiv)</command>
59 <command>prependHttpEquiv($keyValue, $content, $conditionalHttpEquiv)</command>
65 <command>setHttpEquiv($keyValue, $content, $modifiers)</command>
71 <command>setCharset($charset)</command>
77 The <varname>$keyValue</varname> item is used to define a value for the 'name'
78 or 'http-equiv' key; <varname>$content</varname> is the value for the
79 'content' key, and <varname>$modifiers</varname> is an optional associative
80 array that can contain keys for 'lang' and/or 'scheme'.
84 You may also set meta tags using the <methodname>headMeta()</methodname> helper
85 method, which has the following signature: <command>headMeta($content,
86 $keyValue, $keyType = 'name', $modifiers = array(), $placement =
87 'APPEND')</command>. <varname>$keyValue</varname> is the content for the key
88 specified in <varname>$keyType</varname>, which should be either 'name' or
89 'http-equiv'. <varname>$placement</varname> can be either 'SET' (overwrites
90 all previously stored values), 'APPEND' (added to end of stack), or
91 'PREPEND' (added to top of stack).
95 <classname>HeadMeta</classname> overrides each of <methodname>append()</methodname>,
96 <methodname>offsetSet()</methodname>, <methodname>prepend()</methodname>, and
97 <methodname>set()</methodname> to enforce usage of the special methods as listed above.
98 Internally, it stores each item as a <property>stdClass</property> token, which it later
99 serializes using the <methodname>itemToString()</methodname> method. This allows you
100 to perform checks on the items in the stack, and optionally modify these
101 items by simply modifying the object returned.
105 The <classname>HeadMeta</classname> helper is a concrete implementation of the
106 <link linkend="zend.view.helpers.initial.placeholder">Placeholder helper</link>.
109 <example id="zend.view.helpers.initial.headmeta.basicusage">
110 <title>HeadMeta Helper Basic Usage</title>
113 You may specify a new meta tag at any time. Typically, you
114 will specify client-side caching rules or SEO keywords.
118 For instance, if you wish to specify SEO keywords, you'd be creating
119 a meta name tag with the name 'keywords' and the content the
120 keywords you wish to associate with your page:
123 <programlisting language="php"><![CDATA[
124 // setting meta keywords
125 $this->headMeta()->appendName('keywords', 'framework, PHP, productivity');
129 If you wished to set some client-side caching rules, you'd set
130 http-equiv tags with the rules you wish to enforce:
133 <programlisting language="php"><![CDATA[
134 // disabling client-side cache
135 $this->headMeta()->appendHttpEquiv('expires',
136 'Wed, 26 Feb 1997 08:21:57 GMT')
137 ->appendHttpEquiv('pragma', 'no-cache')
138 ->appendHttpEquiv('Cache-Control', 'no-cache');
142 Another popular use for meta tags is setting the content type,
143 character set, and language:
146 <programlisting language="php"><![CDATA[
147 // setting content type and character set
148 $this->headMeta()->appendHttpEquiv('Content-Type',
149 'text/html; charset=UTF-8')
150 ->appendHttpEquiv('Content-Language', 'en-US');
154 If you are serving an HTML5 document, you should provide the character set like this:
157 <programlisting language="php"><![CDATA[
158 // setting character set in HTML5
159 $this->headMeta()->setCharset('UTF-8'); // Will look like <meta charset="UTF-8">
163 As a final example, an easy way to display a transitional message
164 before a redirect is using a "meta refresh":
167 <programlisting language="php"><![CDATA[
168 // setting a meta refresh for 3 seconds to a new url:
169 $this->headMeta()->appendHttpEquiv('Refresh',
170 '3;URL=http://www.some.org/some.html');
174 When you're ready to place your meta tags in the layout, simply echo the helper:
177 <programlisting language="php"><![CDATA[
178 <?php echo $this->headMeta() ?>