<HTML ><HEAD ><TITLE >template_exists()</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Smarty Manual" HREF="index.html"><LINK REL="UP" TITLE="Smarty Class Methods()" HREF="api.functions.html"><LINK REL="PREVIOUS" TITLE="trigger_error()" HREF="api.trigger.error.html"><LINK REL="NEXT" TITLE="unregister_block()" HREF="api.unregister.block.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Smarty Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="api.trigger.error.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="api.unregister.block.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="api.template.exists" ></A >template_exists()</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6471" ></A >template_exists() -- checks whether the specified template exists</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6474" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >template_exists</B > ( string template)<BR ></BR ><P > It can accept either a path to the template on the filesystem or a resource string specifying the template. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6483" ></A ><P ><B >Example 13-1. template_exists()</B ></P ><P > This example uses <TT CLASS="literal" >$_GET['page']</TT > to <A HREF="language.function.include.html" ><TT CLASS="varname" >{include}</TT ></A > a content template. If the template does not exist then an error page is displayed instead. First the <TT CLASS="filename" >page_container.tpl</TT > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <html><br /><head><title>{$title}</title></head><br /><body><br />{include file='page_top.tpl'}<br /><br />{* include middle content page *}<br />{include file=$content_template}<br /><br />{include file='page_footer.tpl'}<br /></body></span> </code></TD ></TR ></TABLE ><P > And the php script </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// set the filename eg index.inc.tpl<br /></span><span style="color: #0000BB">$mid_template </span><span style="color: #007700">= </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'page'</span><span style="color: #007700">].</span><span style="color: #DD0000">'.inc.tpl'</span><span style="color: #007700">;<br /><br />if( !</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">template_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$mid_template</span><span style="color: #007700">) ){<br /> </span><span style="color: #0000BB">$mid_template </span><span style="color: #007700">= </span><span style="color: #DD0000">'page_not_found.tpl'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'content_template'</span><span style="color: #007700">, </span><span style="color: #0000BB">$mid_template</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">display</span><span style="color: #007700">(</span><span style="color: #DD0000">'page_container.tpl'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="api.display.html" ><TT CLASS="varname" >display()</TT ></A >, <A HREF="api.fetch.html" ><TT CLASS="varname" >fetch()</TT ></A >, <A HREF="language.function.include.html" ><TT CLASS="varname" >{include}</TT ></A > and <A HREF="language.function.insert.html" ><TT CLASS="varname" >{insert}</TT ></A > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="api.trigger.error.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="api.unregister.block.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >trigger_error()</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="api.functions.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >unregister_block()</TD ></TR ></TABLE ></DIV ></BODY ></HTML >