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

{eval}

{eval} dipakai untuk mengevaluasi sebuah variabel sebagai template. Ini bisa dgunakan untuk hal seperti menyertakan tag/variabel template ke dalam variabel atau tag/variabel template ke dalam file config.

Jika anda menyertakan atribut assign, output dari fungsi {eval} akan ditempatkan ke variabel template ini daripada ke template.

Nama AtributTipeDiperlukanDefaultDeskripsi
varmixedYan/aVariabel (atau string) untuk mengevaluasi
assignstringTidakn/aVariabel template yang akan ditempati output to

Catatan Teknis:

  • Variabel yang dievaluasi diperlakukan sama seperti template. Mengikuti fitur pengeluaran dan keamanan yang sama seolah-olah sebuah template.

  • Variabel yang dievaluasi dikompilasi setiap kali permintaan, versi terkompilasi tidak disimpan! Akan tetapi jika anda menghidupkan caching, output akan di-cache dengan sisa template.

Teladan 8-6. {eval}

Isi dari file config, setup.conf.

emphstart = <strong>
emphend = </strong>
title = Welcome to {$company}'s home page!
ErrorCity = You must supply a {#emphstart#}city{#emphend#}.
ErrorState = You must supply a {#emphstart#}state{#emphend#}.

Di mana template adalah:

{config_load file='setup.conf'}

{eval var=$foo}
{eval var=#title#}
{eval var=#ErrorCity#}
{eval var=#ErrorState# assign='state_error'}
{$state_error}

Template di atas akan menampilkan:

This is the contents of foo.
Welcome to Foobar Pub & Grill's home page!
You must supply a <strong>city</strong>.
You must supply a <strong>state</strong>.

Teladan 8-7. Contoh {eval} lainnya

Ini menampilkan nama server (in uppercase) dan IP. Variabel yang ditempati $str berasal dari query database.

assign(\'foo\',$str); ?>'); ?>

Di mana template adalah:

{eval var=$foo}
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 5 plus 1? (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