mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-09 16:51:47 +01:00
155 lines
3.9 KiB
XML
155 lines
3.9 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 id="language.function.eval">
|
|
<title>{eval}</title>
|
|
<para>
|
|
<varname>{eval}</varname> 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.
|
|
</para>
|
|
<para>
|
|
Jika anda menyertakan atribut <parameter>assign</parameter>, output dari
|
|
fungsi <varname>{eval}</varname> akan ditempatkan ke variabel template
|
|
ini daripada ke template.
|
|
</para>
|
|
|
|
<informaltable frame="all">
|
|
<tgroup cols="5">
|
|
<colspec colname="param" align="center" />
|
|
<colspec colname="type" align="center" />
|
|
<colspec colname="required" align="center" />
|
|
<colspec colname="default" align="center" />
|
|
<colspec colname="desc" />
|
|
<thead>
|
|
<row>
|
|
<entry>Nama Atribut</entry>
|
|
<entry>Tipe</entry>
|
|
<entry>Diperlukan</entry>
|
|
<entry>Default</entry>
|
|
<entry>Deskripsi</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>var</entry>
|
|
<entry>mixed</entry>
|
|
<entry>Ya</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Variabel (atau string) untuk mengevaluasi</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>string</entry>
|
|
<entry>Tidak</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Variabel template yang akan ditempati output
|
|
to</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
|
|
<note>
|
|
<title>Catatan Teknis</title>
|
|
<para>
|
|
<itemizedlist>
|
|
<listitem><para>
|
|
Variabel yang dievaluasi diperlakukan sama seperti template. Mengikuti
|
|
fitur pengeluaran dan keamanan yang sama seolah-olah sebuah template.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Variabel yang dievaluasi dikompilasi setiap kali permintaan, versi
|
|
terkompilasi tidak disimpan! Akan tetapi jika anda menghidupkan
|
|
<link linkend="caching">caching</link>, output akan di-cache
|
|
dengan sisa template.
|
|
</para></listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
</note>
|
|
|
|
<example>
|
|
<title>{eval}</title>
|
|
<para>Isi dari file config, <filename>setup.conf</filename>.</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
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#}.
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Di mana template adalah:
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{config_load file='setup.conf'}
|
|
|
|
{eval var=$foo}
|
|
{eval var=#title#}
|
|
{eval var=#ErrorCity#}
|
|
{eval var=#ErrorState# assign='state_error'}
|
|
{$state_error}
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Template di atas akan menampilkan:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
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>.
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Contoh {eval} lainnya</title>
|
|
<para>Ini menampilkan nama server (in uppercase) dan IP. Variabel yang
|
|
ditempati <parameter>$str</parameter> berasal dari query database.</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$str = 'The server name is {$smarty.server.SERVER_NAME|upper} '
|
|
.'at {$smarty.server.SERVER_ADDR}';
|
|
$smarty->assign('foo',$str);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Di mana template adalah:
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{eval var=$foo}
|
|
]]>
|
|
</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
|
|
--> |