Files
smarty/docs/it/designers/language-builtin-functions/language-function-section.xml

570 lines
17 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="language.function.section">
<title>section,sectionelse</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>name</entry>
<entry>stringa</entry>
<entry>s<EFBFBD></entry>
<entry><emphasis>nessuno</emphasis></entry>
<entry>Nome della sezione</entry>
</row>
<row>
<entry>loop</entry>
<entry>[$variable_name]</entry>
<entry>s<EFBFBD></entry>
<entry><emphasis>nessuno</emphasis></entry>
<entry>Nome della variabile che determina il numero
di iterazioni del ciclo</entry>
</row>
<row>
<entry>start</entry>
<entry>intero</entry>
<entry>no</entry>
<entry><emphasis>0</emphasis></entry> <entry>L'indice
dal quale inizier<65> il ciclo. Se il valore <20> negativo,
la posizione di partenza <20> calcolata dalla fine dell'array.
Ad esempio, se ci sono sette valori nell'array da ciclare
e start <20> -2, l'indice di partenza sar<61> 5. Valori non
validi (cio<69> al di fuori della lunghezza dell'array da
ciclare) saranno automaticamente convertiti al valore
valido pi<70> vicino.</entry>
</row>
<row>
<entry>step</entry>
<entry>intero</entry>
<entry>no</entry>
<entry><emphasis>1</emphasis></entry>
<entry>Il valore di passo da usare per attraversare
l'array da ciclare. Ad esempio, step=2 cicler<65> sugli
indici 0,2,4, ecc. Se step <20> negativo il ciclo proceder<65>
sull'array all'indietro.</entry>
</row>
<row>
<entry>max</entry>
<entry>intero</entry>
<entry>no</entry>
<entry><emphasis>nessuno</emphasis></entry>
<entry>Massimo numero di cicli per la sezione.</entry>
</row>
<row>
<entry>show</entry>
<entry>booleano</entry>
<entry>no</entry>
<entry><emphasis>true</emphasis></entry>
<entry>Stabilisce se mostrare o no la sezione</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Le sezioni sono usate per ciclare su array di dati. Tutti i tag
<emphasis>section</emphasis> devono essere chiusi con
<emphasis>/section</emphasis>. I parametri obbligatori sono
<emphasis>name</emphasis> e <emphasis>loop</emphasis>. Il nome
della sezione pu<70> essere quello che preferite, formato da lettere,
numeri e underscore. Le sezioni possono essere nidificate, ed i nomi
delle sezioni nidificate devono essere diversi fra loro. La variabile
loop (di solito un array di valori) determina quante volte sar<61>
eseguito il ciclo. Quando stampate una variabile all'interno di una
sezione, il nome della sezione deve essere indicato a fianco del
nome della variabile fra parentesi quadre [].
<emphasis>sectionelse</emphasis> viene eseguito quando non ci sono
valori nella variabile loop.
</para>
<example>
<title>section</title>
<programlisting>
{* questo esempio stamper<65> tutti i valori dell'array $custid *}
{section name=customer loop=$custid}
id: {$custid[customer]}&lt;br&gt;
{/section}
OUTPUT:
id: 1000&lt;br&gt;
id: 1001&lt;br&gt;
id: 1002&lt;br&gt;</programlisting>
</example>
<example>
<title>variabile loop</title>
<programlisting>
{* la variabile loop determina soltanto il numero di cicli da ripetere.
Potete accedere a qualsiasi variabile dal template della sezione.
In questo esempio presumiamo che $custid, $name e $address siano
tutti array contenenti lo stesso numero di valori *}
{section name=customer loop=$custid}
id: {$custid[customer]}&lt;br&gt;
name: {$name[customer]}&lt;br&gt;
address: {$address[customer]}&lt;br&gt;
&lt;p&gt;
{/section}
OUTPUT:
id: 1000&lt;br&gt;
name: John Smith&lt;br&gt;
address: 253 N 45th&lt;br&gt;
&lt;p&gt;
id: 1001&lt;br&gt;
name: Jack Jones&lt;br&gt;
address: 417 Mulberry ln&lt;br&gt;
&lt;p&gt;
id: 1002&lt;br&gt;
name: Jane Munson&lt;br&gt;
address: 5605 apple st&lt;br&gt;
&lt;p&gt;</programlisting>
</example>
<example>
<title>nomi delle sezioni</title>
<programlisting>
{* come nome della sezione potete usare quello che preferite,
e viene usato per riferirsi ai dati all'interno della sezione *}
{section name=mydata loop=$custid}
id: {$custid[mydata]}&lt;br&gt;
name: {$name[mydata]}&lt;br&gt;
address: {$address[mydata]}&lt;br&gt;
&lt;p&gt;
{/section}</programlisting>
</example>
<example>
<title>sezioni nidificate</title>
<programlisting>
{* le sezioni possono essere nidificate a qualsiasi profondit<69>. Con
le sezioni nidificate potete accedere a strutture di dati complesse,
ad esempio array multidimensionali. In questo esempio, $contact_type[customer]
<20> un array di tipi di contatto per il cliente corrente. *}
{section name=customer loop=$custid}
id: {$custid[customer]}&lt;br&gt;
name: {$name[customer]}&lt;br&gt;
address: {$address[customer]}&lt;br&gt;
{section name=contact loop=$contact_type[customer]}
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}&lt;br&gt;
{/section}
&lt;p&gt;
{/section}
OUTPUT:
id: 1000&lt;br&gt;
name: John Smith&lt;br&gt;
address: 253 N 45th&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: john@myexample.com&lt;br&gt;
&lt;p&gt;
id: 1001&lt;br&gt;
name: Jack Jones&lt;br&gt;
address: 417 Mulberry ln&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: jack@myexample.com&lt;br&gt;
&lt;p&gt;
id: 1002&lt;br&gt;
name: Jane Munson&lt;br&gt;
address: 5605 apple st&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: jane@myexample.com&lt;br&gt;
&lt;p&gt;</programlisting>
</example>
<example>
<title>sezioni e array associativi</title>
<programlisting>
{* questo <20> un esempio di stampa di un array associativo
di dati in una sezione *}
{section name=customer loop=$contacts}
name: {$contacts[customer].name}&lt;br&gt;
home: {$contacts[customer].home}&lt;br&gt;
cell: {$contacts[customer].cell}&lt;br&gt;
e-mail: {$contacts[customer].email}&lt;p&gt;
{/section}
OUTPUT:
name: John Smith&lt;br&gt;
home: 555-555-5555&lt;br&gt;
cell: 555-555-5555&lt;br&gt;
e-mail: john@myexample.com&lt;p&gt;
name: Jack Jones&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: jack@myexample.com&lt;p&gt;
name: Jane Munson&lt;br&gt;
home phone: 555-555-5555&lt;br&gt;
cell phone: 555-555-5555&lt;br&gt;
e-mail: jane@myexample.com&lt;p&gt;</programlisting>
</example>
<example>
<title>sectionelse</title>
<programlisting>
{* sectionelse viene eseguito se non ci sono valori in $custid *}
{section name=customer loop=$custid}
id: {$custid[customer]}&lt;br&gt;
{sectionelse}
there are no values in $custid.
{/section}</programlisting>
</example>
<para>
Le sezioni hanno anche le proprie variabili di gestione delle propriet<65>.
Vengono indicate cos<6F>: {$smarty.section.nomesezione.nomevariabile}
</para>
<note>
<para>
A partire da Smarty 1.5.0, la sintassi per le variabili delle propriet<65>
di sessione <20> cambiata da {%nomesezione.nomevariabile%} a
{$smarty.section.sectionname.varname}. La vecchia sintassi <20> ancora
supportata, ma negli esempi del manuale troverete solo riferimenti
alla nuova.
</para>
</note>
<sect2 id="section.property.index">
<title>index</title>
<para>
index si usa per visualizzare l'attuale indice del ciclo, partendo
da zero (o dall'attributo start se presente), e con incrementi di uno
(o dell'attributo step se presente).
</para>
<note>
<title>Nota tecnica</title>
<para>
Se le propriet<65> step e start non vengono modificate, index
funziona allo stesso modo della propriet<65> iteration, ad
eccezione del fatto che parte da 0 invece che da 1.
</para>
</note>
<example>
<title>propriet<EFBFBD> index</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{/section}
OUTPUT:
0 id: 1000&lt;br&gt;
1 id: 1001&lt;br&gt;
2 id: 1002&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.index.prev">
<title>index_prev</title>
<para>
index_prev visualizza l'indice del ciclo precedente.
Sul primo ciclo <20> impostata a -1.
</para>
<example>
<title>propriet<EFBFBD> index_prev</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{* nota: $custid[customer.index] e $custid[customer] hanno identico significato *}
{if $custid[customer.index_prev] ne $custid[customer.index]}
The customer id changed&lt;br&gt;
{/if}
{/section}
OUTPUT:
0 id: 1000&lt;br&gt;
The customer id changed&lt;br&gt;
1 id: 1001&lt;br&gt;
The customer id changed&lt;br&gt;
2 id: 1002&lt;br&gt;
The customer id changed&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.index.next">
<title>index_next</title>
<para>
index_next visualizza l'indice del prossimo ciclo. Sull'ultimo
ciclo ha sempre il valore maggiore dell'attuale (rispettando
l'attributo step, quando presente).
</para>
<example>
<title>propriet<EFBFBD> index_next</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{* nota: $custid[customer.index] e $custid[customer] hanno identico significato *}
{if $custid[customer.index_next] ne $custid[customer.index]}
The customer id will change&lt;br&gt;
{/if}
{/section}
OUTPUT:
0 id: 1000&lt;br&gt;
The customer id will change&lt;br&gt;
1 id: 1001&lt;br&gt;
The customer id will change&lt;br&gt;
2 id: 1002&lt;br&gt;
The customer id will change&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.iteration">
<title>iteration</title>
<para>
iteration visualizza l'iterazione attuale del ciclo.
</para>
<note>
<para>
Al contrario di index, questa propriet<65> non <20> influenzata dalle
propriet<65> start, step e max. Inoltre iteration comincia da 1
invece che da 0 come index. rownum <20> un alias di iteration, e
funziona in modo identico.
</para>
</note>
<example>
<title>propriet<EFBFBD> iteration</title>
<programlisting>
{section name=customer loop=$custid start=5 step=2}
current loop iteration: {$smarty.section.customer.iteration}&lt;br&gt;
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{* nota: $custid[customer.index] e $custid[customer] hanno identico significato *}
{if $custid[customer.index_next] ne $custid[customer.index]}
The customer id will change&lt;br&gt;
{/if}
{/section}
OUTPUT:
current loop iteration: 1
5 id: 1000&lt;br&gt;
The customer id will change&lt;br&gt;
current loop iteration: 2
7 id: 1001&lt;br&gt;
The customer id will change&lt;br&gt;
current loop iteration: 3
9 id: 1002&lt;br&gt;
The customer id will change&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.first">
<title>first</title>
<para>
first vale true se l'iterazione attuale <20> la prima.
</para>
<example>
<title>propriet<EFBFBD> first</title>
<programlisting>
{section name=customer loop=$custid}
{if $smarty.section.customer.first}
&lt;table&gt;
{/if}
&lt;tr&gt;&lt;td&gt;{$smarty.section.customer.index} id:
{$custid[customer]}&lt;/td&gt;&lt;/tr&gt;
{if $smarty.section.customer.last}
&lt;/table&gt;
{/if}
{/section}
OUTPUT:
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;0 id: 1000&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;1 id: 1001&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2 id: 1002&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.last">
<title>last</title>
<para>
last vale true se l'attuale iterazione <20> l'ultima.
</para>
<example>
<title>propriet<EFBFBD> last</title>
<programlisting>
{section name=customer loop=$custid}
{if $smarty.section.customer.first}
&lt;table&gt;
{/if}
&lt;tr&gt;&lt;td&gt;{$smarty.section.customer.index} id:
{$custid[customer]}&lt;/td&gt;&lt;/tr&gt;
{if $smarty.section.customer.last}
&lt;/table&gt;
{/if}
{/section}
OUTPUT:
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;0 id: 1000&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;1 id: 1001&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2 id: 1002&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.rownum">
<title>rownum</title>
<para>
rownum visualizza l'iterazione attuale del ciclo, partendo
da uno. E' un alias di iteration, e funziona in modo identico.
</para>
<example>
<title>propriet<EFBFBD> rownum</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.rownum} id: {$custid[customer]}&lt;br&gt;
{/section}
OUTPUT:
1 id: 1000&lt;br&gt;
2 id: 1001&lt;br&gt;
3 id: 1002&lt;br&gt;
</programlisting>
</example>
</sect2>
<sect2 id="section.property.loop">
<title>loop</title>
<para>
loop visualizza l'index dell'ultimo ciclo visualizzato dalla
sezione. Pu<50> essere usato all'interno o dopo la sezione.
</para>
<example>
<title>propriet<EFBFBD> index</title>
<programlisting>
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{/section}
There were {$smarty.section.customer.loop} customers shown above.
OUTPUT:
0 id: 1000&lt;br&gt;
1 id: 1001&lt;br&gt;
2 id: 1002&lt;br&gt;
There were 3 customers shown above.
</programlisting>
</example>
</sect2>
<sect2 id="section.property.show">
<title>show</title>
<para>
<emphasis>show</emphasis> <20> usato come parametro per la sezione.
<emphasis>show</emphasis> <20> un valore booleano, true o false. Se
false, la sezione non verr<72> visualizzata. Se <20> presente un sectionelse,
verr<72> visualizzato questo.
</para>
<example>
<title>attributo show</title>
<programlisting>
{* $show_customer_info potrebbe essere stato passato dall'applicazione
PHP, per stabilire se questa sezione deve essere visualizzata o no *}
{section name=customer loop=$custid show=$show_customer_info}
{$smarty.section.customer.rownum} id: {$custid[customer]}&lt;br&gt;
{/section}
{if $smarty.section.customer.show}
the section was shown.
{else}
the section was not shown.
{/if}
OUTPUT:
1 id: 1000&lt;br&gt;
2 id: 1001&lt;br&gt;
3 id: 1002&lt;br&gt;
the section was shown.
</programlisting>
</example>
</sect2>
<sect2 id="section.property.total">
<title>total</title>
<para>
total visualizza il numero totale di iterazioni che la sezione
eseguir<69>. Pu<50> essere usato all'interno o dopo la sezione.
</para>
<example>
<title>propriet<EFBFBD> total</title>
<programlisting>
{section name=customer loop=$custid step=2}
{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
{/section}
There were {$smarty.section.customer.total} customers shown above.
OUTPUT:
0 id: 1000&lt;br&gt;
2 id: 1001&lt;br&gt;
4 id: 1002&lt;br&gt;
There were 3 customers shown above.
</programlisting>
</example>
</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
-->