mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-09 00:31:45 +01:00
217 lines
6.1 KiB
XML
217 lines
6.1 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 id="language.function.include">
|
|
<title>{include}</title>
|
|
<para>
|
|
Tag <varname>{include}</varname> dipakai untuk menyertakan template lain
|
|
dalam template saat ini. Setiap variabel yang tersedia dalam template
|
|
saat ini juga tersedia di dalam template yang disertakan.
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
<listitem><para>
|
|
Tag <varname>{include}</varname> harus mempunyai atribut
|
|
<parameter>file</parameter> yang berisi path sumber daya template.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Menyetel atribut opsional <parameter>assign</parameter> menetapkan variabel
|
|
template yang menempatkan <varname>{include}</varname> ke output, daripada
|
|
ditampilkan. Mirip dengan
|
|
<link linkend="language.function.assign"><varname>{assign}</varname></link>.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Variabel bisa dikirimkan ke template yang disertakan sebagai
|
|
<link linkend="language.syntax.attributes">atribut</link>.
|
|
Setiap variabel yang dikirimkan secara eksplisit ke template
|
|
yang disertakan hanya tersedia di dalam lingkup file yang
|
|
disertakan. Variabel atribut menimpa variabel template saat
|
|
ini, dalam hal ketika bernama sama.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Semua nilai variabel yang ditempatkan dikembalikan setelah lingkup
|
|
template yang disertakan tidak ada. Ini berarti anda dapat menggunakan
|
|
semua variabel termasuk template di dalam template yang disertakan.
|
|
Tapi perubahan variabel di dalam template yang disertakan tidak terlihat
|
|
di dalam template yang menyertakan setelah pernyataan
|
|
<varname>{include}</varname>.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Gunakan sintaks <link linkend="template.resources">sumber daya template</link>
|
|
untuk <varname>{include}</varname> file di luar direktori
|
|
<link linkend="variable.template.dir"><parameter>$template_dir</parameter></link>.
|
|
</para></listitem>
|
|
</itemizedlist>
|
|
|
|
<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>file</entry>
|
|
<entry>string</entry>
|
|
<entry>Ya</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Nama file template yang disertakan</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>string</entry>
|
|
<entry>Tidak</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Nama variabel yang outputnya akan ditempati</entry>
|
|
</row>
|
|
<row>
|
|
<entry>[var ...]</entry>
|
|
<entry>[var type]</entry>
|
|
<entry>Tidak</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>variabel untuk mengirimkan lokal ke template</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
|
|
<example>
|
|
<title>Contoh {include} sederhana</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
<html>
|
|
<head>
|
|
<title>{$title}</title>
|
|
</head>
|
|
<body>
|
|
{include file='page_header.tpl'}
|
|
|
|
{* badan template di sini, variabel $tpl_name diganti dengan
|
|
nilai misalnya 'contact.tpl'
|
|
*}
|
|
{include file="$tpl_name.tpl"}
|
|
|
|
{include file='page_footer.tpl'}
|
|
</body>
|
|
</html>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<example>
|
|
<title>variabel pengiriman {include}</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{include file='links.tpl' title='Newest links' links=$link_array}
|
|
{* badan template di sini *}
|
|
{include file='footer.tpl' foo='bar'}
|
|
]]>
|
|
</programlisting>
|
|
<para>Template di atas menyertakan contoh <filename>links.tpl</filename>
|
|
di bawah ini.</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
<div id="box">
|
|
<h3>{$title}{/h3>
|
|
<ul>
|
|
{foreach from=$links item=l}
|
|
.. do stuff ...
|
|
</foreach}
|
|
</ul>
|
|
</div>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
|
|
<example>
|
|
<title>{include} and assign to variable</title>
|
|
<para>This example assigns the contents of <filename>nav.tpl</filename>
|
|
to the <varname>$navbar</varname> variable,
|
|
which is then output at both the top and bottom of the page.
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
<body>
|
|
{include file='nav.tpl' assign=navbar}
|
|
{include file='header.tpl' title='Smarty is cool'}
|
|
{$navbar}
|
|
{* badan template di sini *}
|
|
{$navbar}
|
|
{include file='footer.tpl'}
|
|
</body>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Contoh berbagai sumber daya {include}</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{* path file absolut *}
|
|
{include file='/usr/local/include/templates/header.tpl'}
|
|
|
|
{* path file absolut (hal yang sama) *}
|
|
{include file='file:/usr/local/include/templates/header.tpl'}
|
|
|
|
{* path file windows absolut (HARUS menggunakan prefiks "file:") *}
|
|
{include file='file:C:/www/pub/templates/header.tpl'}
|
|
|
|
{* sertakan dari sumber daya template bernama "db" *}
|
|
{include file='db:header.tpl'}
|
|
|
|
{* sertakan $variable template - misal $module = 'contacts' *}
|
|
{include file="$module.tpl"}
|
|
|
|
{* tidak akan bekerja karena tanda kutip tunggal, tidak ada penggantian variabel *}
|
|
{include file='$module.tpl'}
|
|
|
|
{* sertakan template multi $variabel - misal amber/links.view.tpl *}
|
|
{include file="$style_dir/$module.$view.tpl"}
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<para>
|
|
Lihat juga
|
|
<link linkend="language.function.include.php"><varname>{include_php}</varname></link>,
|
|
<link linkend="language.function.insert"><varname>{insert}</varname></link>,
|
|
<link linkend="language.function.php"><varname>{php}</varname></link>,
|
|
<link linkend="template.resources">sumber daya template</link> dan
|
|
<link linkend="tips.componentized.templates">mengkomponenkan template</link>.
|
|
</para>
|
|
</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
|
|
-->
|
|
|