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

96 lines
2.8 KiB
XML
Raw Normal View History

2007-04-21 12:13:34 +00:00
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
2009-06-14 07:23:39 +00:00
<!-- EN-Revision: 2972 Maintainer: takagi Status: ready -->
2007-04-21 12:13:34 +00:00
<!-- CREDITS: mat-sh,daichi,joe -->
<refentry id="api.template.exists">
<refnamediv>
<refname>template_exists()</refname>
<refpurpose>指定したテンプレートが存在するかどうかをチェックします。</refpurpose>
</refnamediv>
<refsect1>
<title>説明</title>
<methodsynopsis>
<type>bool</type><methodname>template_exists</methodname>
<methodparam><type>string</type><parameter>template</parameter></methodparam>
</methodsynopsis>
<para>
ファイルシステムに関するテンプレートへのパス
又はテンプレートを指定するリソースの文字列のいずれかを受け入れる事ができます。
</para>
<example>
<title>template_exists()</title>
<para>
この例は、コンテンツテンプレートを
<link linkend="language.function.include"><varname>インクルード</varname></link>
するのに <literal>$_GET['page']</literal> を使用しています。
テンプレートが存在しない場合、代わりにエラーページが表示されます。
まずは <filename>page_container.tpl</filename> から。
</para>
<programlisting role="php">
<![CDATA[
<html>
<head><title>{$title}</title></head>
<body>
{include file='page_top.tpl'}
{* コンテンツページの中央部分をインクルード *}
{include file=$content_template}
{include file='page_footer.tpl'}
</body>
]]>
</programlisting>
<para>
そしてスクリプトです。
</para>
<programlisting role="php">
<![CDATA[
<?php
// 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>
<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>
および
<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
-->