Files
smarty/docs/id/programmers/api-functions/api-template-exists.xml

93 lines
2.4 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<refentry id="api.template.exists">
<refnamediv>
<refname>template_exists()</refname>
<refpurpose>memeiksa apakah template yang ditetapkan sudah ada</refpurpose>
</refnamediv>
<refsect1>
<title>Deskripsi</title>
<methodsynopsis>
<type>bool</type><methodname>template_exists</methodname>
<methodparam><type>string</type><parameter>template</parameter></methodparam>
</methodsynopsis>
<para>
Ini dapat menerima baik path ke template pada sistem file ataupun string
sumber daya yang menetapkan template.
</para>
<example>
<title>template_exists()</title>
<para>
Contoh ini menggunakan <literal>$_GET['page']</literal> untuk
<link linkend="language.function.include"><varname>{include}</varname></link>
konten template. Jika template tidak ada maka halaman kesalahan yang
ditampilkan. Pertama <filename>page_container.tpl</filename>
</para>
<programlisting role="php">
<![CDATA[
<html>
<head><title>{$title}</title></head>
<body>
{include file='page_top.tpl'}
{* sertakan halaman konten tengah *}
{include file=$content_template}
{include file='page_footer.tpl'}
</body>
]]>
</programlisting>
<para>
Dan naskah php
</para>
<programlisting role="php">
<![CDATA[
<?php
// set nama file, contoh index.inc.tpl
$mid_template = $_GET['page'].'.inc.tpl';
if( !$smarty->template_exists($mid_template) ){
$mid_template = 'page_not_found.tpl';
}
$smarty->assign('content_template', $mid_template);
$smarty->display('page_container.tpl');
?>
]]>
</programlisting>
</example>
<para>
Lihat juga
<link linkend="api.display"><varname>display()</varname></link>,
<link linkend="api.fetch"><varname>fetch()</varname></link>,
<link linkend="language.function.include"><varname>{include}</varname></link>
and
<link linkend="language.function.insert"><varname>{insert}</varname></link>
</para>
</refsect1>
</refentry>
<!-- 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
-->