Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

if,elseif,else

Los comandos {if} del Smarty tiene mucho de la flexibilidad del comando if de php, con algunas adiciones para la herramienta de template. Todo {if} debe tener su {/if}. {else} y {elseif} también son permitidos. Toda las condicionales de PHP son reconcidas, tal como ||, or, &&, and, etc.

La siguiente es una lista de calificadores reconocidos, los cuales deberan estar separados los dos elementos por espacios. Nota loas articulos pueden listarse [entre corchetes] es opcional. Equivalentes al lugar donde se apliquen en PHP.

Calificador Alternativa Ejemplo de Sintaxis Significado Equivalente en PHP
== eq $a eq $b Iguales ==
!= ne, neq $a neq $b Diferentes !=
> gt $a gt $b Mayor que >
< lt $a lt $b menor que <
>= gte, ge $a ge $b mayor que o igual >=
<= lte, le $a le $b menor que o igual <=
===   $a === 0 Igual e indentico ===
! not not $a negación (unary) !
% mod $a mod $b modulo %
is [not] div by   $a is not div by 4 divisible por $a % $b == 0
is [not] even   $a is not even [not] es numero par (unary) $a % 2 == 0
is [not] even by   $a is not even by $b agrupar niveles pares [not] ($a / $b) % 2 == 0
is [not] odd   $a is not odd [not] el numero es impar (unary) $a % 2 != 0
is [not] odd by   $a is not odd by $b [not] agrupa los niveles impares ($a / $b) % 2 != 0

Example 7.13. sentencia if


{if $name eq "Fred"}
	Welcome Sir.
{elseif $name eq "Wilma"}
	Welcome Ma'am.
{else}
	Welcome, whatever you are.
{/if}

{* Un ejemplo con "or" logico *}
{if $name eq "Fred" or $name eq "Wilma"}
	...
{/if}

{* El mismo que arriba *}
{if $name == "Fred" || $name == "Wilma"}
	...
{/if}

{* La siguiente sintaxis no funcionara, el calificador de condición
   deben estar separados entre ellos por espacios *}
{if $name=="Fred" || $name=="Wilma"}
	...
{/if}


{* los parentesis son permitidos *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
	...
{/if}

{* Usted también puede colocar funciones de PHP *}
{if count($var) gt 0}
	...
{/if}

{* checa si el valor es par o impar *}
{if $var is even}
	...
{/if}
{if $var is odd}
	...
{/if}
{if $var is not odd}
	...
{/if}

{* checa si la variable  var es divisible por 4 *}
{if $var is div by 4}
	...
{/if}

{* Checa si la variable var es igual, agrupandola por dos. 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}


Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 13 plus 18? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk