mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-15 15:09:51 +01:00
added italian docs. thanks to Gianluca Gillini
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="language.function.foreach">
|
||||
<title>foreach,foreachelse</title>
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="5">
|
||||
<colspec colname="param" align="center" />
|
||||
<colspec colname="type" align="center" />
|
||||
<colspec colname="required" align="center" />
|
||||
<colspec colname="default" align="center" />
|
||||
<colspec colname="desc" />
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Nome Attributo</entry>
|
||||
<entry>Tipo</entry>
|
||||
<entry>Obbligatorio</entry>
|
||||
<entry>Default</entry>
|
||||
<entry>Descrizione</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>from</entry>
|
||||
<entry>array</entry>
|
||||
<entry>s<EFBFBD></entry>
|
||||
<entry><emphasis>nessuno</emphasis></entry>
|
||||
<entry>Array sul quale viene eseguito il ciclo</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>item</entry>
|
||||
<entry>stringa</entry>
|
||||
<entry>s<EFBFBD></entry>
|
||||
<entry><emphasis>nessuno</emphasis></entry>
|
||||
<entry>Nome della variabile che rappresenta
|
||||
l'elemento attuale</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>key</entry>
|
||||
<entry>stringa</entry>
|
||||
<entry>no</entry>
|
||||
<entry><emphasis>nessuno</emphasis></entry>
|
||||
<entry>Nome della variabile che rappresenta la chiave attuale</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>name</entry>
|
||||
<entry>stringa</entry>
|
||||
<entry>no</entry>
|
||||
<entry><emphasis>nessuno</emphasis></entry>
|
||||
<entry>Nome del ciclo foreach per l'accesso alle sue propriet<65></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
<para>
|
||||
I cicli <emphasis>foreach</emphasis> sono un'alternativa ai cicli
|
||||
<emphasis>section</emphasis>. <emphasis>foreach</emphasis> si usa
|
||||
per ciclare su un singolo array associativo. La sintassi di
|
||||
<emphasis>foreach</emphasis> <20> molto pi<70> semplice di
|
||||
<emphasis>session</emphasis>, ma in compenso pu<70> essere usata solo
|
||||
per un array singolo. I tag <emphasis>foreach</emphasis> devono
|
||||
essere chiusi con <emphasis>/foreach</emphasis>. I parametri
|
||||
obbligatori sono <emphasis>from</emphasis> e <emphasis>item</emphasis>.
|
||||
Il nome del ciclo foreach pu<70> essere quello che preferite, composto
|
||||
di lettere, numeri e underscore. I cicli <emphasis>foreach</emphasis>
|
||||
possono essere nidificati, ma i nomi dei cicli nidificati devono
|
||||
essere diversi tra di loro. La variabile <emphasis>from</emphasis>
|
||||
(di solito un array di valori) determina quante volte verr<72> eseguito
|
||||
il ciclo <emphasis>foreach</emphasis>.
|
||||
<emphasis>foreachelse</emphasis> viene eseguito quando non ci sono
|
||||
valori nella variabile <emphasis>from</emphasis>.
|
||||
</para>
|
||||
<example>
|
||||
<title>foreach</title>
|
||||
<programlisting>
|
||||
|
||||
{* questo esempio stamper<65> tutti i valori dell'array $custid *}
|
||||
{foreach from=$custid item=curr_id}
|
||||
id: {$curr_id}<br>
|
||||
{/foreach}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
id: 1000<br>
|
||||
id: 1001<br>
|
||||
id: 1002<br></programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>foreach con key</title>
|
||||
<programlisting>
|
||||
{* key contiene la chiave per ogni valore del ciclo
|
||||
|
||||
l'assegnazione pu<70> essere qualcosa del genere:
|
||||
|
||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||
|
||||
*}
|
||||
|
||||
{foreach name=outer item=contact from=$contacts}
|
||||
{foreach key=key item=item from=$contact}
|
||||
{$key}: {$item}<br>
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
phone: 1<br>
|
||||
fax: 2<br>
|
||||
cell: 3<br>
|
||||
phone: 555-4444<br>
|
||||
fax: 555-3333<br>
|
||||
cell: 760-1234<br></programlisting>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
I cicli foreach hanno anche le proprie variabili che gestiscono le propriet<65>
|
||||
del foreach. Queste vengono indicate cos<6F>: {$smarty.foreach.foreachname.varname},
|
||||
dove foreachname <20> il nome indicato come attributo <emphasis>name</emphasis>
|
||||
del foreach
|
||||
</para>
|
||||
|
||||
|
||||
<sect2 id="foreach.property.iteration">
|
||||
<title>iteration</title>
|
||||
<para>
|
||||
iteration si usa per mostrare l'iterazione corrente del ciclo.
|
||||
</para>
|
||||
<para>
|
||||
iteration comincia sempre per 1 ed <20> incrementata di uno
|
||||
ad ogni iterazione.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="foreach.property.first">
|
||||
<title>first</title>
|
||||
<para>
|
||||
<emphasis>first</emphasis> vale true quando l'iterazione attuale <20> la prima del ciclo.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="foreach.property.last">
|
||||
<title>last</title>
|
||||
<para>
|
||||
<emphasis>last</emphasis> vale true quando l'iterazione attuale <20> l'ultima del ciclo.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="foreach.property.show">
|
||||
<title>show</title>
|
||||
<para>
|
||||
<emphasis>show</emphasis> si usa come parametro per il foreach.
|
||||
<emphasis>show</emphasis> <20> un valore booleano, true o false. Quando
|
||||
<09> false, il foreach non verr<72> visualizzato. Se <20> presente un
|
||||
foreachelse, verr<72> visualizzato al suo posto.
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
<sect2 id="foreach.property.total">
|
||||
<title>total</title>
|
||||
<para>
|
||||
<emphasis>total</emphasis> si usa per visualizzare il numero di iterazioni che il
|
||||
ciclo foreach effettuer<65>. Pu<50> essere usato all'interno o dopo il foreach.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
indent-tabs-mode:nil
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"../../../../manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
||||
Reference in New Issue
Block a user