PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/documentation/it/designers/language-builtin-functions/language-function-foreach.xml

https://bitbucket.org/hallgrennetworks/smarty
XML | 191 lines | 148 code | 22 blank | 21 comment | 0 complexity | 16fb5d7616682e9e16b9edeb9e27b809 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- $Revision: 2972 $ -->
  3. <sect1 id="language.function.foreach">
  4. <title>foreach,foreachelse</title>
  5. <informaltable frame="all">
  6. <tgroup cols="5">
  7. <colspec colname="param" align="center" />
  8. <colspec colname="type" align="center" />
  9. <colspec colname="required" align="center" />
  10. <colspec colname="default" align="center" />
  11. <colspec colname="desc" />
  12. <thead>
  13. <row>
  14. <entry>Nome Attributo</entry>
  15. <entry>Tipo</entry>
  16. <entry>Obbligatorio</entry>
  17. <entry>Default</entry>
  18. <entry>Descrizione</entry>
  19. </row>
  20. </thead>
  21. <tbody>
  22. <row>
  23. <entry>from</entry>
  24. <entry>array</entry>
  25. <entry></entry>
  26. <entry><emphasis>nessuno</emphasis></entry>
  27. <entry>Array sul quale viene eseguito il ciclo</entry>
  28. </row>
  29. <row>
  30. <entry>item</entry>
  31. <entry>stringa</entry>
  32. <entry></entry>
  33. <entry><emphasis>nessuno</emphasis></entry>
  34. <entry>Nome della variabile che rappresenta
  35. l'elemento attuale</entry>
  36. </row>
  37. <row>
  38. <entry>key</entry>
  39. <entry>stringa</entry>
  40. <entry>no</entry>
  41. <entry><emphasis>nessuno</emphasis></entry>
  42. <entry>Nome della variabile che rappresenta la chiave attuale</entry>
  43. </row>
  44. <row>
  45. <entry>name</entry>
  46. <entry>stringa</entry>
  47. <entry>no</entry>
  48. <entry><emphasis>nessuno</emphasis></entry>
  49. <entry>Nome del ciclo foreach per l'accesso alle sue proprietà</entry>
  50. </row>
  51. </tbody>
  52. </tgroup>
  53. </informaltable>
  54. <para>
  55. I cicli <emphasis>foreach</emphasis> sono un'alternativa ai cicli
  56. <emphasis>section</emphasis>. <emphasis>foreach</emphasis> si usa
  57. per ciclare su un singolo array associativo. La sintassi di
  58. <emphasis>foreach</emphasis> è molto più semplice di
  59. <emphasis>session</emphasis>, ma in compenso può essere usata solo
  60. per un array singolo. I tag <emphasis>foreach</emphasis> devono
  61. essere chiusi con <emphasis>/foreach</emphasis>. I parametri
  62. obbligatori sono <emphasis>from</emphasis> e <emphasis>item</emphasis>.
  63. Il nome del ciclo foreach può essere quello che preferite, composto
  64. di lettere, numeri e underscore. I cicli <emphasis>foreach</emphasis>
  65. possono essere nidificati, ma i nomi dei cicli nidificati devono
  66. essere diversi tra di loro. La variabile <emphasis>from</emphasis>
  67. (di solito un array di valori) determina quante volte verrà eseguito
  68. il ciclo <emphasis>foreach</emphasis>.
  69. <emphasis>foreachelse</emphasis> viene eseguito quando non ci sono
  70. valori nella variabile <emphasis>from</emphasis>.
  71. </para>
  72. <example>
  73. <title>foreach</title>
  74. <programlisting>
  75. {* questo esempio stamperà tutti i valori dell'array $custid *}
  76. {foreach from=$custid item=curr_id}
  77. id: {$curr_id}&lt;br&gt;
  78. {/foreach}
  79. OUTPUT:
  80. id: 1000&lt;br&gt;
  81. id: 1001&lt;br&gt;
  82. id: 1002&lt;br&gt;</programlisting>
  83. </example>
  84. <example>
  85. <title>foreach con key</title>
  86. <programlisting>
  87. {* key contiene la chiave per ogni valore del ciclo
  88. l'assegnazione può essere qualcosa del genere:
  89. $smarty->assign("contacts", array(array("phone" =&gt; "1", "fax" =&gt; "2", "cell" =&gt; "3"),
  90. array("phone" =&gt; "555-4444", "fax" =&gt; "555-3333", "cell" =&gt; "760-1234")));
  91. *}
  92. {foreach name=outer item=contact from=$contacts}
  93. {foreach key=key item=item from=$contact}
  94. {$key}: {$item}&lt;br&gt;
  95. {/foreach}
  96. {/foreach}
  97. OUTPUT:
  98. phone: 1&lt;br&gt;
  99. fax: 2&lt;br&gt;
  100. cell: 3&lt;br&gt;
  101. phone: 555-4444&lt;br&gt;
  102. fax: 555-3333&lt;br&gt;
  103. cell: 760-1234&lt;br&gt;</programlisting>
  104. </example>
  105. <para>
  106. I cicli foreach hanno anche le proprie variabili che gestiscono le proprietà
  107. del foreach. Queste vengono indicate così: {$smarty.foreach.foreachname.varname},
  108. dove foreachname è il nome indicato come attributo <emphasis>name</emphasis>
  109. del foreach
  110. </para>
  111. <sect2 id="foreach.property.iteration">
  112. <title>iteration</title>
  113. <para>
  114. iteration si usa per mostrare l'iterazione corrente del ciclo.
  115. </para>
  116. <para>
  117. iteration comincia sempre per 1 ed è incrementata di uno
  118. ad ogni iterazione.
  119. </para>
  120. </sect2>
  121. <sect2 id="foreach.property.first">
  122. <title>first</title>
  123. <para>
  124. <emphasis>first</emphasis> vale true quando l'iterazione attuale è la prima del ciclo.
  125. </para>
  126. </sect2>
  127. <sect2 id="foreach.property.last">
  128. <title>last</title>
  129. <para>
  130. <emphasis>last</emphasis> vale true quando l'iterazione attuale è l'ultima del ciclo.
  131. </para>
  132. </sect2>
  133. <sect2 id="foreach.property.show">
  134. <title>show</title>
  135. <para>
  136. <emphasis>show</emphasis> si usa come parametro per il foreach.
  137. <emphasis>show</emphasis> è un valore booleano, true o false. Quando
  138. è false, il foreach non verrà visualizzato. Se è presente un
  139. foreachelse, verrà visualizzato al suo posto.
  140. </para>
  141. </sect2>
  142. <sect2 id="foreach.property.total">
  143. <title>total</title>
  144. <para>
  145. <emphasis>total</emphasis> si usa per visualizzare il numero di iterazioni che il
  146. ciclo foreach effettuerà. Può essere usato all'interno o dopo il foreach.
  147. </para>
  148. </sect2>
  149. </sect1>
  150. <!-- Keep this comment at the end of the file
  151. Local variables:
  152. mode: sgml
  153. sgml-omittag:t
  154. sgml-shorttag:t
  155. sgml-minimize-attributes:nil
  156. sgml-always-quote-attributes:t
  157. sgml-indent-step:1
  158. sgml-indent-data:t
  159. indent-tabs-mode:nil
  160. sgml-parent-document:nil
  161. sgml-default-dtd-file:"../../../../manual.ced"
  162. sgml-exposed-tags:nil
  163. sgml-local-catalogs:nil
  164. sgml-local-ecat-files:nil
  165. End:
  166. vim600: syn=xml fen fdm=syntax fdl=2 si
  167. vim: et tw=78 syn=sgml
  168. vi: ts=1 sw=1
  169. -->