Zend_View-Helpers-HeadMeta.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 <code>&lt;meta&gt;</code> 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 <code>HeadMeta</code> helper supports the following methods for
  14. setting and adding meta tags:
  15. </para>
  16. <itemizedlist>
  17. <listitem><para><code>appendName($keyValue, $content,
  18. $conditionalName)</code></para></listitem>
  19. <listitem><para><code>offsetSetName($index, $keyValue, $content,
  20. $conditionalName)</code></para></listitem>
  21. <listitem><para><code>prependName($keyValue, $content,
  22. $conditionalName)</code></para></listitem>
  23. <listitem><para><code>setName($keyValue, $content,
  24. $modifiers)</code></para></listitem>
  25. <listitem><para><code>appendHttpEquiv($keyValue, $content,
  26. $conditionalHttpEquiv)</code></para></listitem>
  27. <listitem><para><code>offsetSetHttpEquiv($index, $keyValue, $content,
  28. $conditionalHttpEquiv)</code></para></listitem>
  29. <listitem><para><code>prependHttpEquiv($keyValue, $content,
  30. $conditionalHttpEquiv)</code></para></listitem>
  31. <listitem><para><code>setHttpEquiv($keyValue, $content,
  32. $modifiers)</code></para></listitem>
  33. </itemizedlist>
  34. <para>
  35. The <code>$keyValue</code> item is used to define a value for the 'name'
  36. or 'http-equiv' key; <code>$content</code> is the value for the
  37. 'content' key, and <code>$modifiers</code> is an optional associative
  38. array that can contain keys for 'lang' and/or 'scheme'.
  39. </para>
  40. <para>
  41. You may also set meta tags using the <code>headMeta()</code> helper
  42. method, which has the following signature: <code>headMeta($content,
  43. $keyValue, $keyType = 'name', $modifiers = array(), $placement =
  44. 'APPEND')</code>. <code>$keyValue</code> is the content for the key
  45. specified in <code>$keyType</code>, which should be either 'name' or
  46. 'http-equiv'. <code>$placement</code> can be either 'SET' (overwrites
  47. all previously stored values), 'APPEND' (added to end of stack), or
  48. 'PREPEND' (added to top of stack).
  49. </para>
  50. <para>
  51. <code>HeadMeta</code> overrides each of <code>append()</code>,
  52. <code>offsetSet()</code>, <code>prepend()</code>, and <code>set()</code>
  53. to enforce usage of the special methods as listed above. Internally, it
  54. stores each item as a <code>stdClass</code> token, which it later
  55. serializes using the <code>itemToString()</code> method. This allows you
  56. to perform checks on the items in the stack, and optionally modify these
  57. items by simply modifying the object returned.
  58. </para>
  59. <para>
  60. The <code>HeadMeta</code> helper is a concrete implementation of the
  61. <link linkend="zend.view.helpers.initial.placeholder">Placeholder
  62. helper</link>.
  63. </para>
  64. <example id="zend.view.helpers.initial.headmeta.basicusage">
  65. <title>HeadMeta Helper Basic Usage</title>
  66. <para>
  67. You may specify a new meta tag at any time. Typically, you
  68. will specify client-side caching rules or SEO keywords.
  69. </para>
  70. <para>
  71. For instance, if you wish to specify SEO keywords, you'd be creating
  72. a meta name tag with the name 'keywords' and the content the
  73. keywords you wish to associate with your page:
  74. </para>
  75. <programlisting language="php"><![CDATA[
  76. // setting meta keywords
  77. $this->headMeta()->appendName('keywords', 'framework php productivity');
  78. ]]></programlisting>
  79. <para>
  80. If you wished to set some client-side caching rules, you'd set
  81. http-equiv tags with the rules you wish to enforce:
  82. </para>
  83. <programlisting language="php"><![CDATA[
  84. // disabling client-side cache
  85. $this->headMeta()->appendHttpEquiv('expires',
  86. 'Wed, 26 Feb 1997 08:21:57 GMT')
  87. ->appendHttpEquiv('pragma', 'no-cache')
  88. ->appendHttpEquiv('Cache-Control', 'no-cache');
  89. ]]></programlisting>
  90. <para>
  91. Another popular use for meta tags is setting the content type,
  92. character set, and language:
  93. </para>
  94. <programlisting language="php"><![CDATA[
  95. // setting content type and character set
  96. $this->headMeta()->appendHttpEquiv('Content-Type',
  97. 'text/html; charset=UTF-8')
  98. ->appendHttpEquiv('Content-Language', 'en-US');
  99. ]]></programlisting>
  100. <para>
  101. As a final example, an easy way to display a transitional message
  102. before a redirect is using a "meta refresh":
  103. </para>
  104. <programlisting language="php"><![CDATA[
  105. // setting a meta refresh for 3 seconds to a new url:
  106. $this->headMeta()->appendHttpEquiv('Refresh',
  107. '3;URL=http://www.some.org/some.html');
  108. ]]></programlisting>
  109. <para>
  110. When you're ready to place your meta tags in the layout, simply echo
  111. the helper:
  112. </para>
  113. <programlisting language="php"><![CDATA[
  114. <?php echo $this->headMeta() ?>
  115. ]]></programlisting>
  116. </example>
  117. </sect3>
  118. <!--
  119. vim:se ts=4 sw=4 et:
  120. -->