Zend_View-Helpers-HeadMeta.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 <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 helper</link>.
  92. </para>
  93. <example id="zend.view.helpers.initial.headmeta.basicusage">
  94. <title>HeadMeta Helper Basic Usage</title>
  95. <para>
  96. You may specify a new meta tag at any time. Typically, you
  97. will specify client-side caching rules or SEO keywords.
  98. </para>
  99. <para>
  100. For instance, if you wish to specify SEO keywords, you'd be creating
  101. a meta name tag with the name 'keywords' and the content the
  102. keywords you wish to associate with your page:
  103. </para>
  104. <programlisting language="php"><![CDATA[
  105. // setting meta keywords
  106. $this->headMeta()->appendName('keywords', 'framework, PHP, productivity');
  107. ]]></programlisting>
  108. <para>
  109. If you wished to set some client-side caching rules, you'd set
  110. http-equiv tags with the rules you wish to enforce:
  111. </para>
  112. <programlisting language="php"><![CDATA[
  113. // disabling client-side cache
  114. $this->headMeta()->appendHttpEquiv('expires',
  115. 'Wed, 26 Feb 1997 08:21:57 GMT')
  116. ->appendHttpEquiv('pragma', 'no-cache')
  117. ->appendHttpEquiv('Cache-Control', 'no-cache');
  118. ]]></programlisting>
  119. <para>
  120. Another popular use for meta tags is setting the content type,
  121. character set, and language:
  122. </para>
  123. <programlisting language="php"><![CDATA[
  124. // setting content type and character set
  125. $this->headMeta()->appendHttpEquiv('Content-Type',
  126. 'text/html; charset=UTF-8')
  127. ->appendHttpEquiv('Content-Language', 'en-US');
  128. ]]></programlisting>
  129. <para>
  130. If you are serving an <acronym>HTML</acronym>5 document, you should provide the
  131. character set like this:
  132. </para>
  133. <programlisting language="php"><![CDATA[
  134. // setting character set in HTML5
  135. $this->headMeta()->setCharset('UTF-8'); // Will look like <meta charset="UTF-8">
  136. ]]></programlisting>
  137. <para>
  138. As a final example, an easy way to display a transitional message
  139. before a redirect is using a "meta refresh":
  140. </para>
  141. <programlisting language="php"><![CDATA[
  142. // setting a meta refresh for 3 seconds to a new url:
  143. $this->headMeta()->appendHttpEquiv('Refresh',
  144. '3;URL=http://www.some.org/some.html');
  145. ]]></programlisting>
  146. <para>
  147. When you're ready to place your meta tags in the layout, simply echo the helper:
  148. </para>
  149. <programlisting language="php"><![CDATA[
  150. <?php echo $this->headMeta() ?>
  151. ]]></programlisting>
  152. </example>
  153. </sect3>
  154. <!--
  155. vim:se ts=4 sw=4 et:
  156. -->