Zend_View-Helpers-HeadMeta.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 HTML <emphasis>&lt;meta&gt;</emphasis> element is used to provide meta
  7. information about your HTML 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 <varname>$keyValue</varname> item is used to define a value for the 'name'
  66. or 'http-equiv' key; <varname>$content</varname> is the value for the
  67. 'content' key, and <varname>$modifiers</varname> is an optional associative
  68. array that can contain keys for 'lang' and/or 'scheme'.
  69. </para>
  70. <para>
  71. You may also set meta tags using the <methodname>headMeta()</methodname> helper
  72. method, which has the following signature: <command>headMeta($content,
  73. $keyValue, $keyType = 'name', $modifiers = array(), $placement =
  74. 'APPEND')</command>. <varname>$keyValue</varname> is the content for the key
  75. specified in <varname>$keyType</varname>, which should be either 'name' or
  76. 'http-equiv'. <varname>$placement</varname> can be either 'SET' (overwrites
  77. all previously stored values), 'APPEND' (added to end of stack), or
  78. 'PREPEND' (added to top of stack).
  79. </para>
  80. <para>
  81. <classname>HeadMeta</classname> overrides each of <methodname>append()</methodname>,
  82. <methodname>offsetSet()</methodname>, <methodname>prepend()</methodname>, and
  83. <methodname>set()</methodname> to enforce usage of the special methods as listed above.
  84. Internally, it stores each item as a <property>stdClass</property> token, which it later
  85. serializes using the <methodname>itemToString()</methodname> method. This allows you
  86. to perform checks on the items in the stack, and optionally modify these
  87. items by simply modifying the object returned.
  88. </para>
  89. <para>
  90. The <classname>HeadMeta</classname> helper is a concrete implementation of the
  91. <link linkend="zend.view.helpers.initial.placeholder">Placeholder
  92. helper</link>.
  93. </para>
  94. <example id="zend.view.helpers.initial.headmeta.basicusage">
  95. <title>HeadMeta Helper Basic Usage</title>
  96. <para>
  97. You may specify a new meta tag at any time. Typically, you
  98. will specify client-side caching rules or SEO keywords.
  99. </para>
  100. <para>
  101. For instance, if you wish to specify SEO keywords, you'd be creating
  102. a meta name tag with the name 'keywords' and the content the
  103. keywords you wish to associate with your page:
  104. </para>
  105. <programlisting language="php"><![CDATA[
  106. // setting meta keywords
  107. $this->headMeta()->appendName('keywords', 'framework, PHP, productivity');
  108. ]]></programlisting>
  109. <para>
  110. If you wished to set some client-side caching rules, you'd set
  111. http-equiv tags with the rules you wish to enforce:
  112. </para>
  113. <programlisting language="php"><![CDATA[
  114. // disabling client-side cache
  115. $this->headMeta()->appendHttpEquiv('expires',
  116. 'Wed, 26 Feb 1997 08:21:57 GMT')
  117. ->appendHttpEquiv('pragma', 'no-cache')
  118. ->appendHttpEquiv('Cache-Control', 'no-cache');
  119. ]]></programlisting>
  120. <para>
  121. Another popular use for meta tags is setting the content type,
  122. character set, and language:
  123. </para>
  124. <programlisting language="php"><![CDATA[
  125. // setting content type and character set
  126. $this->headMeta()->appendHttpEquiv('Content-Type',
  127. 'text/html; charset=UTF-8')
  128. ->appendHttpEquiv('Content-Language', 'en-US');
  129. ]]></programlisting>
  130. <para>
  131. If you are serving an HTML5 document, you should provide the character
  132. set like this:
  133. </para>
  134. <programlisting language="php"><![CDATA[
  135. // setting character set in HTML5
  136. $this->headMeta()->setCharset('UTF-8'); // Will look like <meta charset="UTF-8">
  137. ]]></programlisting>
  138. <para>
  139. As a final example, an easy way to display a transitional message
  140. before a redirect is using a "meta refresh":
  141. </para>
  142. <programlisting language="php"><![CDATA[
  143. // setting a meta refresh for 3 seconds to a new url:
  144. $this->headMeta()->appendHttpEquiv('Refresh',
  145. '3;URL=http://www.some.org/some.html');
  146. ]]></programlisting>
  147. <para>
  148. When you're ready to place your meta tags in the layout, simply echo
  149. the helper:
  150. </para>
  151. <programlisting language="php"><![CDATA[
  152. <?php echo $this->headMeta() ?>
  153. ]]></programlisting>
  154. </example>
  155. </sect3>
  156. <!--
  157. vim:se ts=4 sw=4 et:
  158. -->