mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 06:11:37 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			97 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			97 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
<?xml version="1.0" encoding="iso-8859-1"?>
 | 
						|
<!-- $Revision$ -->
 | 
						|
<refentry id="api.template.exists">
 | 
						|
 <refnamediv>
 | 
						|
  <refname>template_exists()</refname>
 | 
						|
  <refpurpose>checks whether the specified template exists</refpurpose>
 | 
						|
 </refnamediv>
 | 
						|
 <refsect1>
 | 
						|
  <title>Description</title>
 | 
						|
  <methodsynopsis>
 | 
						|
   <type>bool</type><methodname>template_exists</methodname>
 | 
						|
   <methodparam><type>string</type><parameter>template</parameter></methodparam>
 | 
						|
  </methodsynopsis>
 | 
						|
  <para>
 | 
						|
   It can  accept either a path to the template on the filesystem or a
 | 
						|
   resource string specifying the template.
 | 
						|
  </para>
 | 
						|
 | 
						|
  <example>
 | 
						|
  <title>template_exists()</title>
 | 
						|
    <para>
 | 
						|
    This example uses $_GET['page'] to include a content template. If
 | 
						|
    the template  doesnt exist then an error page is displayed instead.
 | 
						|
    </para>
 | 
						|
    <para>
 | 
						|
    The <filename>page_container.tpl</filename>
 | 
						|
    </para>
 | 
						|
    <programlisting role="php">
 | 
						|
<![CDATA[
 | 
						|
<html>
 | 
						|
<head><title>{$title}</title></head>
 | 
						|
<body>
 | 
						|
{include file='page_top.tpl'}
 | 
						|
 | 
						|
{* include middle content page *}
 | 
						|
{include file=$page_mid}
 | 
						|
 | 
						|
{include file='page_footer.tpl'}
 | 
						|
</body>
 | 
						|
]]>
 | 
						|
  </programlisting>
 | 
						|
  <para>
 | 
						|
  and the php script
 | 
						|
  </para>
 | 
						|
  <programlisting role="php">
 | 
						|
<![CDATA[
 | 
						|
<?php
 | 
						|
 | 
						|
// set the filename eg index.inc.tpl
 | 
						|
$mid_template = $_GET['page'].'.inc.tpl';
 | 
						|
 | 
						|
if( !$smarty->template_exists($mid_template) ){
 | 
						|
    $mid_template = 'page_not_found.inc.tpl';
 | 
						|
}
 | 
						|
$smarty->assign('page_mid', $mid_template);
 | 
						|
 | 
						|
$smarty->display('page_container.tpl');
 | 
						|
 | 
						|
?>
 | 
						|
]]>
 | 
						|
  </programlisting>
 | 
						|
  </example>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
  <para>
 | 
						|
  See also
 | 
						|
  <link linkend="api.display">display()</link>,
 | 
						|
  <link linkend="api.fetch">fetch()</link>,
 | 
						|
  <link linkend="language.function.include">{include}</link>
 | 
						|
  and
 | 
						|
  <link linkend="language.function.insert">{insert}</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
 | 
						|
-->
 |