mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 14:21:36 +01:00 
			
		
		
		
	
		
			
	
	
		
			220 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			220 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| 
								 | 
							
								<?xml version="1.0" encoding="iso-8859-1"?>
							 | 
						|||
| 
								 | 
							
								<!-- $Revision$ -->
							 | 
						|||
| 
								 | 
							
										<sect1 id="language.function.if">
							 | 
						|||
| 
								 | 
							
											<title>if,elseif,else</title>
							 | 
						|||
| 
								 | 
							
											<para>
							 | 
						|||
| 
								 | 
							
											Le istruzioni <emphasis>{if}</emphasis> in Smarty hanno praticamente la 
							 | 
						|||
| 
								 | 
							
											stessa flessibilit<69> delle istruzioni if PHP, con qualche caratteristica
							 | 
						|||
| 
								 | 
							
											aggiuntiva per il motore di template.
							 | 
						|||
| 
								 | 
							
											Ogni <emphasis>{if}</emphasis> deve essere chiuso con un
							 | 
						|||
| 
								 | 
							
											<emphasis>{/if}</emphasis>. Sono previsti anche <emphasis>{else}</emphasis>
							 | 
						|||
| 
								 | 
							
											e <emphasis>{elseif}</emphasis>. Sono riconosciuti tutti gli operatori condizionali
							 | 
						|||
| 
								 | 
							
											di PHP, come <emphasis>||</emphasis>, <emphasis>or</emphasis>,
							 | 
						|||
| 
								 | 
							
								            <emphasis>&&</emphasis>, <emphasis>and</emphasis>, ecc.
							 | 
						|||
| 
								 | 
							
											</para>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
											<para>
							 | 
						|||
| 
								 | 
							
									    Quella che segue <20> una lista degli operatori riconosciuti, che devono
							 | 
						|||
| 
								 | 
							
									    essere separati con degli spazi dagli elementi circostanti. Notate che
							 | 
						|||
| 
								 | 
							
									    gli elementi mostrati fra [parentesi quadre] sono opzionali. Quando esistono
							 | 
						|||
| 
								 | 
							
									    sono mostrati gli equivalenti in PHP.
							 | 
						|||
| 
								 | 
							
								            </para>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            <informaltable frame="all">
							 | 
						|||
| 
								 | 
							
								                <tgroup cols="4">
							 | 
						|||
| 
								 | 
							
								                <colspec colname="qualifier" align="center" />
							 | 
						|||
| 
								 | 
							
								                <colspec colname="alternates" align="center" />
							 | 
						|||
| 
								 | 
							
								                <colspec colname="meaning" />
							 | 
						|||
| 
								 | 
							
								                <colspec colname="example" />
							 | 
						|||
| 
								 | 
							
								                <colspec colname="php" />
							 | 
						|||
| 
								 | 
							
								                <thead>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>Operatore</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Alternative</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Esempio di sintassi</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Significato</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>Equivalente PHP</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                </thead>
							 | 
						|||
| 
								 | 
							
								                <tbody>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>==</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>eq</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a eq $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>uguale</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>==</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>!=</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>ne, neq</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a neq $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>diverso</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>!=</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>gt</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a gt $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>maggiore di</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>></entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry><</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>lt</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a lt $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>minore di</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry><</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>>=</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>gte, ge</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a ge $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>maggiore o uguale</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>>=</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry><=</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>lte, le</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a le $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>minore o uguale</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry><=</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>!</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>not</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>not $a</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>negazione (unario)</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>!</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>%</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>mod</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a mod $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>modulo (resto della divisione)</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>%</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>is [not] div by</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a is not div by 4</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>divisibile per</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a % $b == 0</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>is [not] even</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a is not even</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>[non] <20> un numero pari (unario)</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a % 2 == 0</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>is [not] even by</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a is not even by $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>livello di raggruppamento [non] pari</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>($a / $b) % 2 == 0</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>is [not] odd</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a is not odd</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>[non] <20> un numero dispari (unario)</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a % 2 != 0</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                    <row>
							 | 
						|||
| 
								 | 
							
								                        <entry>is [not] odd by</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry></entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>$a is not odd by $b</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>livello di raggruppamento [non] dispari</entry>
							 | 
						|||
| 
								 | 
							
								                        <entry>($a / $b) % 2 != 0</entry>
							 | 
						|||
| 
								 | 
							
								                    </row>
							 | 
						|||
| 
								 | 
							
								                </tbody>
							 | 
						|||
| 
								 | 
							
										  </tgroup>
							 | 
						|||
| 
								 | 
							
									</informaltable>
							 | 
						|||
| 
								 | 
							
								<example>
							 | 
						|||
| 
								 | 
							
								<title>Istruzioni if</title>
							 | 
						|||
| 
								 | 
							
								<programlisting>
							 | 
						|||
| 
								 | 
							
								{if $name eq "Fred"}
							 | 
						|||
| 
								 | 
							
									Welcome Sir.
							 | 
						|||
| 
								 | 
							
								{elseif $name eq "Wilma"}
							 | 
						|||
| 
								 | 
							
									Welcome Ma'am.
							 | 
						|||
| 
								 | 
							
								{else}
							 | 
						|||
| 
								 | 
							
									Welcome, whatever you are.
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* un esempio con "or" logico *}
							 | 
						|||
| 
								 | 
							
								{if $name eq "Fred" or $name eq "Wilma"}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* come sopra *}
							 | 
						|||
| 
								 | 
							
								{if $name == "Fred" || $name == "Wilma"}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* questa sintassi NON funziona, gli operatori condizionali
							 | 
						|||
| 
								 | 
							
								   devono essere separati con spazi dagli elementi circostanti *}
							 | 
						|||
| 
								 | 
							
								{if $name=="Fred" || $name=="Wilma"}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* si possono usare le parentesi *}
							 | 
						|||
| 
								 | 
							
								{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* potete anche incorporare chiamate a funzioni php *}
							 | 
						|||
| 
								 | 
							
								{if count($var) gt 0}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* test su valori pari o dispari *}
							 | 
						|||
| 
								 | 
							
								{if $var is even}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								{if $var is odd}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								{if $var is not odd}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* test se var <20> divisibile per 4 *}
							 | 
						|||
| 
								 | 
							
								{if $var is div by 4}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* test se var <20> pari, raggruppato per due. Ad es.:
							 | 
						|||
| 
								 | 
							
								0=pari, 1=pari, 2=dispari, 3=dispari, 4=pari, 5=pari, etc. *}
							 | 
						|||
| 
								 | 
							
								{if $var is even by 2}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								{* 0=pari, 1=pari, 2=pari, 3=dispari, 4=dispari, 5=dispari, etc. *}
							 | 
						|||
| 
								 | 
							
								{if $var is even by 3}
							 | 
						|||
| 
								 | 
							
									...
							 | 
						|||
| 
								 | 
							
								{/if}</programlisting>
							 | 
						|||
| 
								 | 
							
								</example>
							 | 
						|||
| 
								 | 
							
								</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
							 | 
						|||
| 
								 | 
							
								-->
							 |