<HTML ><HEAD ><TITLE >display()</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="config_load()" HREF="api.config.load.html"><LINK REL="NEXT" TITLE="fetch()" HREF="api.fetch.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.config.load.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="api.fetch.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="api.display" ></A >display()</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN5752" ></A >display() -- displays the template</DIV ><DIV CLASS="refsect1" ><A NAME="AEN5755" ></A ><H2 >Description</H2 >void <B CLASS="methodname" >display</B > ( string template [, string cache_id [, string compile_id]])<BR ></BR ><P > This displays the template unlike <A HREF="api.fetch.html" ><TT CLASS="varname" >fetch()</TT ></A >. Supply a valid <A HREF="template.resources.html" >template resource</A > type and path. As an optional second parameter, you can pass a <TT CLASS="parameter" ><I >$cache id</I ></TT >, see the <A HREF="caching.html" >caching section</A > for more information. </P ><P > As an optional third parameter, you can pass a <TT CLASS="parameter" ><I >$compile_id</I ></TT >. This is in the event that you want to compile different versions of the same template, such as having separate templates compiled for different languages. Another use for <TT CLASS="parameter" ><I >$compile_id</I ></TT > is when you use more than one <A HREF="api.variables.html#variable.template.dir" ><TT CLASS="parameter" ><I >$template_dir</I ></TT ></A > but only one <A HREF="variable.compile.dir.html" ><TT CLASS="parameter" ><I >$compile_dir</I ></TT ></A >. Set a separate <TT CLASS="parameter" ><I >$compile_id</I ></TT > for each <A HREF="api.variables.html#variable.template.dir" ><TT CLASS="parameter" ><I >$template_dir</I ></TT ></A >, otherwise templates of the same name will overwrite each other. You can also set the <A HREF="variable.compile.id.html" > <TT CLASS="parameter" ><I >$compile_id</I ></TT ></A > variable once instead of passing this to each call to this function. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5787" ></A ><P ><B >Example 13-1. display()</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">include(</span><span style="color: #0000BB">SMARTY_DIR</span><span style="color: #007700">.</span><span style="color: #DD0000">'Smarty.class.php'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty </span><span style="color: #007700">= new </span><span style="color: #0000BB">Smarty</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">caching </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// only do db calls if cache doesn't exist<br /></span><span style="color: #007700">if(!</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">is_cached</span><span style="color: #007700">(</span><span style="color: #DD0000">'index.tpl'</span><span style="color: #007700">)) {<br /><br /> </span><span style="color: #FF8000">// dummy up some data<br /> </span><span style="color: #0000BB">$address </span><span style="color: #007700">= </span><span style="color: #DD0000">"245 N 50th"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$db_data </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">"City" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Lincoln"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"State" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Nebraska"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"Zip" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"68502"<br /> </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">"Name"</span><span style="color: #007700">,</span><span style="color: #DD0000">"Fred"</span><span style="color: #007700">);<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">"Address"</span><span style="color: #007700">,</span><span style="color: #0000BB">$address</span><span style="color: #007700">);<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">'data'</span><span style="color: #007700">, </span><span style="color: #0000BB">$db_data</span><span style="color: #007700">);<br /><br />}<br /><br /></span><span style="color: #FF8000">// display the output<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">'index.tpl'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5790" ></A ><P ><B >Example 13-2. Other display() template resource examples</B ></P ><P > Use the syntax for <A HREF="template.resources.html" >template resources</A > to display files outside of the <A HREF="api.variables.html#variable.template.dir" > <TT CLASS="parameter" ><I >$template_dir</I ></TT ></A > directory. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// absolute filepath<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">'/usr/local/include/templates/header.tpl'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// absolute filepath (same thing)<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">'file:/usr/local/include/templates/header.tpl'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// windows absolute filepath (MUST use "file:" prefix)<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">'file:C:/www/pub/templates/header.tpl'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// include from template resource named "db"<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">'db:header.tpl'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="api.fetch.html" ><TT CLASS="varname" >fetch()</TT ></A > and <A HREF="api.template.exists.html" ><TT CLASS="varname" >template_exists()</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.config.load.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.fetch.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >config_load()</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" >fetch()</TD ></TR ></TABLE ></DIV ></BODY ></HTML >