Zend_View-Helpers-HeadMeta.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.view.helpers.initial.headmeta">
  4. <title>HeadMeta Helper</title>
  5. <para>
  6. The <acronym>HTML</acronym> <emphasis>&lt;meta&gt;</emphasis> element is used to provide
  7. meta information about your <acronym>HTML</acronym> document -- typically keywords, document
  8. character set, caching pragmas, etc. Meta tags may be either of the
  9. 'http-equiv' or 'name' types, must contain a 'content' attribute, and
  10. can also have either of the 'lang' or 'scheme' modifier attributes.
  11. </para>
  12. <para>
  13. The <classname>HeadMeta</classname> helper supports the following methods for
  14. setting and adding meta tags:
  15. </para>
  16. <itemizedlist>
  17. <listitem>
  18. <para>
  19. <command>appendName($keyValue, $content, $conditionalName)</command>
  20. </para>
  21. </listitem>
  22. <listitem>
  23. <para>
  24. <command>offsetSetName($index, $keyValue, $content, $conditionalName)</command>
  25. </para>
  26. </listitem>
  27. <listitem>
  28. <para>
  29. <command>prependName($keyValue, $content, $conditionalName)</command>
  30. </para>
  31. </listitem>
  32. <listitem>
  33. <para>
  34. <command>setName($keyValue, $content, $modifiers)</command>
  35. </para>
  36. </listitem>
  37. <listitem>
  38. <para>
  39. <command>appendHttpEquiv($keyValue, $content, $conditionalHttpEquiv)</command>
  40. </para>
  41. </listitem>
  42. <listitem>
  43. <para>
  44. <command>offsetSetHttpEquiv($index, $keyValue, $content,
  45. $conditionalHttpEquiv)</command>
  46. </para>
  47. </listitem>
  48. <listitem>
  49. <para>
  50. <command>prependHttpEquiv($keyValue, $content, $conditionalHttpEquiv)</command>
  51. </para>
  52. </listitem>
  53. <listitem>
  54. <para>
  55. <command>setHttpEquiv($keyValue, $content, $modifiers)</command>
  56. </para>
  57. </listitem>
  58. <listitem>
  59. <para>
  60. <command>setCharset($charset)</command>
  61. </para>
  62. </listitem>
  63. </itemizedlist>
  64. <para>
  65. The following methods are also supported with XHTML1_RDFA doctype
  66. set with the <link linkend="zend.view.helpers.initial.doctype">Doctype helper</link>:
  67. </para>
  68. <itemizedlist>
  69. <listitem>
  70. <para>
  71. <command>appendProperty($property, $content, $modifiers)</command>
  72. </para>
  73. </listitem>
  74. <listitem>
  75. <para>
  76. <command>offsetSetProperty($index, $property, $content, $modifiers)</command>
  77. </para>
  78. </listitem>
  79. <listitem>
  80. <para>
  81. <command>prependProperty($property, $content, $modifiers)</command>
  82. </para>
  83. </listitem>
  84. <listitem>
  85. <para>
  86. <command>setProperty($property, $content, $modifiers)</command>
  87. </para>
  88. </listitem>
  89. </itemizedlist>
  90. <para>
  91. The <varname>$keyValue</varname> item is used to define a value for the 'name'
  92. or 'http-equiv' key; <varname>$content</varname> is the value for the
  93. 'content' key, and <varname>$modifiers</varname> is an optional associative
  94. array that can contain keys for 'lang' and/or 'scheme'.
  95. </para>
  96. <para>
  97. You may also set meta tags using the <methodname>headMeta()</methodname> helper
  98. method, which has the following signature: <command>headMeta($content,
  99. $keyValue, $keyType = 'name', $modifiers = array(), $placement =
  100. 'APPEND')</command>. <varname>$keyValue</varname> is the content for the key
  101. specified in <varname>$keyType</varname>, which should be either 'name' or
  102. 'http-equiv'. <varname>$keyType</varname> may also be specified as 'property' if the
  103. doctype has been set to XHTML1_RDFA. <varname>$placement</varname> can be 'SET' (overwrites
  104. all previously stored values), 'APPEND' (added to end of stack), or
  105. 'PREPEND' (added to top of stack).
  106. </para>
  107. <para>
  108. <classname>HeadMeta</classname> overrides each of <methodname>append()</methodname>,
  109. <methodname>offsetSet()</methodname>, <methodname>prepend()</methodname>, and
  110. <methodname>set()</methodname> to enforce usage of the special methods as listed above.
  111. Internally, it stores each item as a <property>stdClass</property> token, which it later
  112. serializes using the <methodname>itemToString()</methodname> method. This allows you
  113. to perform checks on the items in the stack, and optionally modify these
  114. items by simply modifying the object returned.
  115. </para>
  116. <para>
  117. The <classname>HeadMeta</classname> helper is a concrete implementation of the
  118. <link linkend="zend.view.helpers.initial.placeholder">Placeholder helper</link>.
  119. </para>
  120. <example id="zend.view.helpers.initial.headmeta.basicusage">
  121. <title>HeadMeta Helper Basic Usage</title>
  122. <para>
  123. You may specify a new meta tag at any time. Typically, you
  124. will specify client-side caching rules or SEO keywords.
  125. </para>
  126. <para>
  127. For instance, if you wish to specify SEO keywords, you'd be creating
  128. a meta name tag with the name 'keywords' and the content the
  129. keywords you wish to associate with your page:
  130. </para>
  131. <programlisting language="php"><![CDATA[
  132. // setting meta keywords
  133. $this->headMeta()->appendName('keywords', 'framework, PHP, productivity');
  134. ]]></programlisting>
  135. <para>
  136. If you wished to set some client-side caching rules, you'd set
  137. http-equiv tags with the rules you wish to enforce:
  138. </para>
  139. <programlisting language="php"><![CDATA[
  140. // disabling client-side cache
  141. $this->headMeta()->appendHttpEquiv('expires',
  142. 'Wed, 26 Feb 1997 08:21:57 GMT')
  143. ->appendHttpEquiv('pragma', 'no-cache')
  144. ->appendHttpEquiv('Cache-Control', 'no-cache');
  145. ]]></programlisting>
  146. <para>
  147. Another popular use for meta tags is setting the content type,
  148. character set, and language:
  149. </para>
  150. <programlisting language="php"><![CDATA[
  151. // setting content type and character set
  152. $this->headMeta()->appendHttpEquiv('Content-Type',
  153. 'text/html; charset=UTF-8')
  154. ->appendHttpEquiv('Content-Language', 'en-US');
  155. ]]></programlisting>
  156. <para>
  157. If you are serving an <acronym>HTML</acronym>5 document, you should provide the
  158. character set like this:
  159. </para>
  160. <programlisting language="php"><![CDATA[
  161. // setting character set in HTML5
  162. $this->headMeta()->setCharset('UTF-8'); // Will look like <meta charset="UTF-8">
  163. ]]></programlisting>
  164. <para>
  165. As a final example, an easy way to display a transitional message
  166. before a redirect is using a "meta refresh":
  167. </para>
  168. <programlisting language="php"><![CDATA[
  169. // setting a meta refresh for 3 seconds to a new url:
  170. $this->headMeta()->appendHttpEquiv('Refresh',
  171. '3;URL=http://www.some.org/some.html');
  172. ]]></programlisting>
  173. <para>
  174. When you're ready to place your meta tags in the layout, simply echo the helper:
  175. </para>
  176. <programlisting language="php"><![CDATA[
  177. <?php echo $this->headMeta() ?>
  178. ]]></programlisting>
  179. </example>
  180. <example id="zend.view.helpers.initial.headmeta.property">
  181. <title>HeadMeta Usage with XHTML1_RDFA doctype</title>
  182. <para>
  183. Enabling the RDFa doctype with the <link linkend="zend.view.helpers.initial.doctype">Doctype helper</link>
  184. enables the use of the 'property' attribute (in addition to the standard 'name' and 'http-equiv') with HeadMeta.
  185. This is commonly used with the Facebook <ulink url="http://opengraphprotocol.org/">Open Graph Protocol</ulink>.
  186. </para>
  187. <para>
  188. For instance, you may specify an open graph page title and type as follows:
  189. </para>
  190. <programlisting language="php"><![CDATA[
  191. $this->doctype(Zend_View_Helper_Doctype::XHTML1_RDFA);
  192. $this->headMeta()->setProperty('og:title', 'my article title');
  193. $this->headMeta()->setProperty('og:type', 'article');
  194. echo $this->headMeta();
  195. // output is:
  196. // <meta property="og:title" content="my article title" />
  197. // <meta property="og:type" content="article" />
  198. ]]></programlisting>
  199. </example>
  200. </sect3>
  201. <!--
  202. vim:se ts=4 sw=4 et:
  203. -->