mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-03 22:01:36 +01:00 
			
		
		
		
	
		
			
	
	
		
			217 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			217 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| 
								 | 
							
								<?xml version="1.0" encoding="iso-8859-1"?>
							 | 
						||
| 
								 | 
							
								<!-- $Revision$ -->
							 | 
						||
| 
								 | 
							
										<sect1 id="language.function.if">
							 | 
						||
| 
								 | 
							
											<title>if,elseif,else</title>
							 | 
						||
| 
								 | 
							
											<para>
							 | 
						||
| 
								 | 
							
											<emphasis>{if}</emphasis> statements in Smarty have much the same flexibility as PHP if
							 | 
						||
| 
								 | 
							
											statements, with a few added features for the template engine.
							 | 
						||
| 
								 | 
							
											Every <emphasis>{if}</emphasis> must be paired with an
							 | 
						||
| 
								 | 
							
											<emphasis>{/if}</emphasis>. <emphasis>{else}</emphasis> and
							 | 
						||
| 
								 | 
							
											<emphasis>{elseif}</emphasis> are also permitted. All PHP conditionals
							 | 
						||
| 
								 | 
							
											are recognized, such as <emphasis>||</emphasis>, <emphasis>or</emphasis>,
							 | 
						||
| 
								 | 
							
								            <emphasis>&&</emphasis>, <emphasis>and</emphasis>, etc.
							 | 
						||
| 
								 | 
							
											</para>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											<para>
							 | 
						||
| 
								 | 
							
								            The following is a list of recognized qualifiers, which must be
							 | 
						||
| 
								 | 
							
								            separated from surrounding elements by spaces. Note that items listed
							 | 
						||
| 
								 | 
							
								            in [brackets] are optional. PHP equivalents are shown where applicable.
							 | 
						||
| 
								 | 
							
								            </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>Qualifier</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>Alternates</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>Syntax Example</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>Meaning</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>PHP Equivalent</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                </thead>
							 | 
						||
| 
								 | 
							
								                <tbody>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>==</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>eq</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a eq $b</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>equals</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>==</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>!=</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>ne, neq</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a neq $b</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>not equals</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>!=</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>></entry>
							 | 
						||
| 
								 | 
							
								                        <entry>gt</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a gt $b</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>greater than</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>></entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry><</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>lt</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a lt $b</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>less than</entry>
							 | 
						||
| 
								 | 
							
								                        <entry><</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>>=</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>gte, ge</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a ge $b</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>greater than or equal</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>>=</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry><=</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>lte, le</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a le $b</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>less than or equal</entry>
							 | 
						||
| 
								 | 
							
								                        <entry><=</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>!</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>not</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>not $a</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>negation (unary)</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>!</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>%</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>mod</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a mod $b</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>modulous</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>%</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>is [not] div by</entry>
							 | 
						||
| 
								 | 
							
								                        <entry></entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a is not div by 4</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>divisible by</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a % $b == 0</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>is [not] even</entry>
							 | 
						||
| 
								 | 
							
								                        <entry></entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a is not even</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>[not] an even number (unary)</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>grouping level [not] even</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>($a / $b) % 2 == 0</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                    <row>
							 | 
						||
| 
								 | 
							
								                        <entry>is [not] odd</entry>
							 | 
						||
| 
								 | 
							
								                        <entry></entry>
							 | 
						||
| 
								 | 
							
								                        <entry>$a is not odd</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>[not] an odd number (unary)</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>[not] an odd grouping</entry>
							 | 
						||
| 
								 | 
							
								                        <entry>($a / $b) % 2 != 0</entry>
							 | 
						||
| 
								 | 
							
								                    </row>
							 | 
						||
| 
								 | 
							
								                </tbody>
							 | 
						||
| 
								 | 
							
										  </tgroup>
							 | 
						||
| 
								 | 
							
									</informaltable>
							 | 
						||
| 
								 | 
							
								<example>
							 | 
						||
| 
								 | 
							
								<title>if statements</title>
							 | 
						||
| 
								 | 
							
								<programlisting>
							 | 
						||
| 
								 | 
							
								{if $name eq "Fred"}
							 | 
						||
| 
								 | 
							
									Welcome Sir.
							 | 
						||
| 
								 | 
							
								{elseif $name eq "Wilma"}
							 | 
						||
| 
								 | 
							
									Welcome Ma'am.
							 | 
						||
| 
								 | 
							
								{else}
							 | 
						||
| 
								 | 
							
									Welcome, whatever you are.
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* an example with "or" logic *}
							 | 
						||
| 
								 | 
							
								{if $name eq "Fred" or $name eq "Wilma"}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* same as above *}
							 | 
						||
| 
								 | 
							
								{if $name == "Fred" || $name == "Wilma"}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* the following syntax will NOT work, conditional qualifiers
							 | 
						||
| 
								 | 
							
								   must be separated from surrounding elements by spaces *}
							 | 
						||
| 
								 | 
							
								{if $name=="Fred" || $name=="Wilma"}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* parenthesis are allowed *}
							 | 
						||
| 
								 | 
							
								{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* you can also embed php function calls *}
							 | 
						||
| 
								 | 
							
								{if count($var) gt 0}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* test if values are even or odd *}
							 | 
						||
| 
								 | 
							
								{if $var is even}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								{if $var is odd}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								{if $var is not odd}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* test if var is divisible by 4 *}
							 | 
						||
| 
								 | 
							
								{if $var is div by 4}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* test if var is even, grouped by two. i.e.,
							 | 
						||
| 
								 | 
							
								0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
							 | 
						||
| 
								 | 
							
								{if $var is even by 2}
							 | 
						||
| 
								 | 
							
									...
							 | 
						||
| 
								 | 
							
								{/if}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, 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
							 | 
						||
| 
								 | 
							
								-->
							 |