Zend_View-Helpers-HeadStyle.xml 8.4 KB

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