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}

Pernyataan {if} dalam Smarty memiliki kesamaan fleksibilitas seperti pernyataan PHP if, dengan beberapa fitur yang ditambahkan untuk mesin template. Setiap {if} harus dipasangkan dengan {/if} yang sama. {else} dan {elseif} juga dibolehkan. Semua kondisional dan fungsi PHP dikenal, seperti ||, or, &&, and, is_array(), dll.

Jika $security dihidupkan, hanya fungsi PHP dari array IF_FUNCS dari $security_settings yang dibolehkan.

Berikut adalah daftar kualifikator yang dikenal yang harus dipisahkan dari elemen yang dikelilingi oleh spasi. Catatan bahwa item terdaftar dalam [kurung] adalah opsional. Persamaan PHP ditampilkan bila memungkinkan.

KualifikatorPembedaContoh SintaksArtiPersamaan PHP
==eq$a eq $bsama==
!=ne, neq$a neq $btidak sama!=
>gt$a gt $blebih besar dari>
<lt$a lt $bkurang dari<
>=gte, ge$a ge $blebih besar atau sama>=
<=lte, le$a le $bkurang dari atau sama<=
=== $a === 0periksa identitas===
!notnot $anegasi (unari)!
%mod$a mod $bmodulus%
is [not] div by $a is not div by 4bisa dibagi dengan$a % $b == 0
is [not] even $a is not even[bukan] angka genap (unari)$a % 2 == 0
is [not] even by $a is not even by $btingkat pengelompokan [bukan] genap($a / $b) % 2 == 0
is [not] odd $a is not odd[bukan] angka ganjil (unari)$a % 2 != 0
is [not] odd by $a is not odd by $b[bukan] pengelompokan ganjil($a / $b) % 2 != 0

Teladan 7-15. pernyataan {if}

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

{* contoh dengan logika "or" *}
{if $name eq 'Fred' or $name eq 'Wilma'}
   ...
{/if}

{* sama seperti di atas *}
{if $name == 'Fred' || $name == 'Wilma'}
   ...
{/if}


{* kurung buka/tutup dibolehkan *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
   ...
{/if}


{* anda juga bisa menyertakan fungsi panggil php *}
{if count($var) gt 0}
   ...
{/if}

{* periksa array. *}
{if is_array($foo) }
   .....
{/if}

{* periksa untuk yang bukan null. *}
{if isset($foo) }
   .....
{/if}


{* uji apakah nilai genap atau ganjil *}
{if $var is even}
   ...
{/if}
{if $var is odd}
   ...
{/if}
{if $var is not odd}
   ...
{/if}


{* uji apakah var bisa dibagi dengan 4 *}
{if $var is div by 4}
   ...
{/if}


{*
  uji apakah var genap, dikelompokan oleh dua. misalnya,
  0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, dst.
*}
{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}

Teladan 7-16. contoh {if} berikutnya

{if isset($name) && $name == 'Blog'}
     {* lakukan sesuatu *}
{elseif $name == $foo}
    {* lakukan sesuatu *}
{/if}

{if is_array($foo) && count($foo) > 0)
    {* lakukan untuk setiap pengulangan *}
{/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 18 plus 20? (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