Zend_View-Helpers-HeadStyle.xml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 20794 -->
  3. <!-- Reviewed: no -->
  4. <sect3 id="zend.view.helpers.initial.headstyle">
  5. <title>Assistente HeadStyle</title>
  6. <para>
  7. O elemento HTML <emphasis>&lt;style&gt;</emphasis> é usado para incluir folhas de estilo
  8. <acronym>CSS</acronym> de forma inline no elemento HTML <emphasis>&lt;head&gt;</emphasis>.
  9. </para>
  10. <note>
  11. <title>Use o HeadLink para "linkar" arquivos CSS</title>
  12. <para>
  13. O <link linkend="zend.view.helpers.initial.headlink">HeadLink</link> deve ser usado para
  14. criar elementos <emphasis>&lt;link&gt;</emphasis> para a inclusão de folhas de estilo
  15. externas. <classname>HeadStyle</classname> é usado quando você deseja definir folhas de
  16. estilo inline.
  17. </para>
  18. </note>
  19. <para>
  20. O assistente <classname>HeadStyle</classname> dá suporte aos seguintes métodos para a
  21. configuração e adição de declarações de folhas de estilo:
  22. </para>
  23. <itemizedlist>
  24. <listitem>
  25. <para>
  26. <command>appendStyle($content, $attributes = array())</command>
  27. </para>
  28. </listitem>
  29. <listitem>
  30. <para>
  31. <command>offsetSetStyle($index, $content, $attributes = array())</command>
  32. </para>
  33. </listitem>
  34. <listitem>
  35. <para>
  36. <command>prependStyle($content, $attributes = array())</command>
  37. </para>
  38. </listitem>
  39. <listitem>
  40. <para>
  41. <command>setStyle($content, $attributes = array())</command>
  42. </para>
  43. </listitem>
  44. </itemizedlist>
  45. <para>
  46. Em todos os casos, <varname>$content</varname> é a verdadeira declaração
  47. <acronym>CSS</acronym>. <varname>$attributes</varname> são quaisquer atributos adicionais
  48. que você dejesa prover para a tag <property>style</property>: lang, title, media, ou dir são
  49. todos admissíveis.
  50. </para>
  51. <note>
  52. <title>Setting Conditional Comments</title>
  53. <para>
  54. <classname>HeadStyle</classname> allows you to wrap the style tag in conditional
  55. comments, which allows you to hide it from specific browsers. To add the conditional
  56. tags, pass the conditional value as part of the <varname>$attributes</varname> parameter
  57. in the method calls.
  58. </para>
  59. <example id="zend.view.helpers.initial.headstyle.conditional">
  60. <title>Headstyle With Conditional Comments</title>
  61. <programlisting language="php"><![CDATA[
  62. // adding scripts
  63. $this->headStyle()->appendStyle($styles, array('conditional' => 'lt IE 7'));
  64. ]]></programlisting>
  65. </example>
  66. </note>
  67. <para>
  68. <classname>HeadStyle</classname> também permite a captura de declarações de estilo; isso
  69. pode ser útil se você quiser criar as declarações através de programação, e então colocá-las
  70. em outro lugar. A utilização disso será mostrada em um exemplo abaixo.
  71. </para>
  72. <para>
  73. Finalmente, você pode usar o método <methodname>headStyle()</methodname> para acrescentar
  74. rapidamente elementos de declaração; a assinatura para isso é
  75. <methodname>headStyle($content$placement = 'APPEND', $attributes = array())</methodname>.
  76. <varname>$placement</varname> deve ser 'APPEND', 'PREPEND', ou 'SET'.
  77. </para>
  78. <para>
  79. <classname>HeadStyle</classname> sobrescreve <methodname>append()</methodname>,
  80. <methodname>offsetSet()</methodname>, <methodname>prepend()</methodname>, e
  81. <methodname>set()</methodname> para forçar o uso dos métodos especiais listados acima.
  82. Internamente ele armazena cada item como um token <property>stdClass</property>, que depois
  83. é serializado usando o método <methodname>itemToString()</methodname>. Isso permite que você
  84. faça verificações nos itens da pilha, e opcionalmente modifique estes itens simplesmente
  85. modificando o objeto retornado.
  86. </para>
  87. <para>
  88. O assistente <classname>HeadStyle</classname> é uma implementação concreta do <link
  89. linkend="zend.view.helpers.initial.placeholder">assistente Placeholder</link>.
  90. </para>
  91. <note>
  92. <title>UTF-8 encoding used by default</title>
  93. <para>
  94. By default, Zend Framework uses <acronym>UTF-8</acronym> as its default encoding, and,
  95. specific to this case, <classname>Zend_View</classname> does as well. Character encoding
  96. can be set differently on the view object itself using the
  97. <methodname>setEncoding()</methodname> method (or the the <varname>encoding</varname>
  98. instantiation parameter). However, since <classname>Zend_View_Interface</classname> does
  99. not define accessors for encoding, it's possible that if you are using a custom view
  100. implementation with this view helper, you will not have a
  101. <methodname>getEncoding()</methodname> method, which is what the view helper uses
  102. internally for determining the character set in which to encode.
  103. </para>
  104. <para>
  105. If you do not want to utilize <acronym>UTF-8</acronym> in such a situation, you will
  106. need to implement a <methodname>getEncoding()</methodname> method in your custom view
  107. implementation.
  108. </para>
  109. </note>
  110. <example id="zend.view.helpers.initial.headstyle.basicusage">
  111. <title>Uso Básico do Assistente HeadStyle</title>
  112. <para>
  113. Você pode especificar uma nova tag de estilo a qualquer momento:
  114. </para>
  115. <programlisting language="php"><![CDATA[
  116. // adding styles
  117. $this->headStyle()->appendStyle($styles);
  118. ]]></programlisting>
  119. <para>
  120. A ordenação é muito importante no <acronym>CSS</acronym>; você talvez tenha que
  121. assegurar que as declarações sejam carregadas em uma ordem específica devido à ordem da
  122. cascata; use as diretivas append, prepend, e offsetSet para lhe auxiliar nessa tarefa:
  123. </para>
  124. <programlisting language="php"><![CDATA[
  125. // Putting styles in order
  126. // place at a particular offset:
  127. $this->headStyle()->offsetSetStyle(100, $customStyles);
  128. // place at end:
  129. $this->headStyle()->appendStyle($finalStyles);
  130. // place at beginning
  131. $this->headStyle()->prependStyle($firstStyles);
  132. ]]></programlisting>
  133. <para>
  134. When you're finally ready to output all style declarations in your
  135. layout script, simply echo the helper:
  136. </para>
  137. <programlisting language="php"><![CDATA[
  138. <?php echo $this->headStyle() ?>
  139. ]]></programlisting>
  140. </example>
  141. <example id="zend.view.helpers.initial.headstyle.capture">
  142. <title>Capturing Style Declarations Using the HeadStyle Helper</title>
  143. <para>
  144. Sometimes you need to generate <acronym>CSS</acronym> style declarations
  145. programmatically. While you could use string concatenation,
  146. heredocs, and the like, often it's easier just to do so by creating
  147. the styles and sprinkling in <acronym>PHP</acronym> tags.
  148. <classname>HeadStyle</classname> lets you do just that, capturing it to the stack:
  149. </para>
  150. <programlisting language="php"><![CDATA[
  151. <?php $this->headStyle()->captureStart() ?>
  152. body {
  153. background-color: <?php echo $this->bgColor ?>;
  154. }
  155. <?php $this->headStyle()->captureEnd() ?>
  156. ]]></programlisting>
  157. <para>
  158. The following assumptions are made:
  159. </para>
  160. <itemizedlist>
  161. <listitem>
  162. <para>
  163. The style declarations will be appended to the stack. If you
  164. wish for them to replace the stack or be added to the top,
  165. you will need to pass 'SET' or 'PREPEND', respectively, as
  166. the first argument to <methodname>captureStart()</methodname>.
  167. </para>
  168. </listitem>
  169. <listitem>
  170. <para>
  171. If you wish to specify any additional attributes for the
  172. <emphasis>&lt;style&gt;</emphasis> tag, pass them in an array as
  173. the second argument to <methodname>captureStart()</methodname>.
  174. </para>
  175. </listitem>
  176. </itemizedlist>
  177. </example>
  178. </sect3>
  179. <!--
  180. vim:se ts=4 sw=4 et:
  181. -->