<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>display()</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="api.functions.html" title="Chapter 13. Smarty Class Methods()"> <link rel="prev" href="api.config.load.html" title="config_load()"> <link rel="next" href="api.fetch.html" title="fetch()"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">display()</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="api.config.load.html">Prev</a> </td> <th width="60%" align="center">Chapter 13. Smarty Class Methods()</th> <td width="20%" align="right"> <a accesskey="n" href="api.fetch.html">Next</a> </td> </tr> </table> <hr> </div> <div class="refentry" title="display()"> <a name="api.display"></a><div class="titlepage"></div> <div class="refnamediv"> <h2>Name</h2> <p>display() — displays the template</p> </div> <div class="refsect1" title="Description"> <a name="id3099805"></a><h2>Description</h2> <code class="methodsynopsis"><span class="type">void </span><span class="methodname">display</span>(<span class="methodparam"><span class="type">string </span><span class="parameter">template</span></span>,<br> <span class="methodparam"><span class="type">string </span><span class="parameter">cache_id</span></span>,<br> <span class="methodparam"><span class="type">string </span><span class="parameter">compile_id</span></span>);</code><p> This displays the template unlike <a class="link" href="api.fetch.html" title="fetch()"><code class="varname">fetch()</code></a>. Supply a valid <a class="link" href="template.resources.html" title="Resources">template resource</a> type and path. As an optional second parameter, you can pass a <em class="parameter"><code>$cache id</code></em>, see the <a class="link" href="caching.html" title="Chapter 14. Caching">caching section</a> for more information. </p> <p> As an optional third parameter, you can pass a <em class="parameter"><code>$compile_id</code></em>. 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 <em class="parameter"><code>$compile_id</code></em> is when you use more than one <a class="link" href="api.variables.html#variable.template.dir" title="$template_dir"><em class="parameter"><code>$template_dir</code></em></a> but only one <a class="link" href="variable.compile.dir.html" title="$compile_dir"><em class="parameter"><code>$compile_dir</code></em></a>. Set a separate <em class="parameter"><code>$compile_id</code></em> for each <a class="link" href="api.variables.html#variable.template.dir" title="$template_dir"><em class="parameter"><code>$template_dir</code></em></a>, otherwise templates of the same name will overwrite each other. You can also set the <a class="link" href="variable.compile.id.html" title="$compile_id"> <em class="parameter"><code>$compile_id</code></em></a> variable once instead of passing this to each call to this function. </p> <div class="example"> <a name="id3100588"></a><p class="title"><b>Example 13.12. display()</b></p> <div class="example-contents"><pre class="programlisting"> <?php include(SMARTY_DIR.'Smarty.class.php'); $smarty = new Smarty(); $smarty->caching = true; // only do db calls if cache doesn't exist if(!$smarty->is_cached('index.tpl')) { // dummy up some data $address = '245 N 50th'; $db_data = array( 'City' => 'Lincoln', 'State' => 'Nebraska', 'Zip' => '68502' ); $smarty->assign('Name', 'Fred'); $smarty->assign('Address', $address); $smarty->assign('data', $db_data); } // display the output $smarty->display('index.tpl'); ?> </pre></div> </div> <br class="example-break"><div class="example"> <a name="id3100634"></a><p class="title"><b>Example 13.13. Other display() template resource examples</b></p> <div class="example-contents"> <p> Use the syntax for <a class="link" href="template.resources.html" title="Resources">template resources</a> to display files outside of the <a class="link" href="api.variables.html#variable.template.dir" title="$template_dir"> <em class="parameter"><code>$template_dir</code></em></a> directory. </p> <pre class="programlisting"> <?php // absolute filepath $smarty->display('/usr/local/include/templates/header.tpl'); // absolute filepath (same thing) $smarty->display('file:/usr/local/include/templates/header.tpl'); // windows absolute filepath (MUST use "file:" prefix) $smarty->display('file:C:/www/pub/templates/header.tpl'); // include from template resource named "db" $smarty->display('db:header.tpl'); ?> </pre> </div> </div> <br class="example-break"><p> See also <a class="link" href="api.fetch.html" title="fetch()"><code class="varname">fetch()</code></a> and <a class="link" href="api.template.exists.html" title="template_exists()"><code class="varname">template_exists()</code></a>. </p> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="api.config.load.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="api.functions.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="api.fetch.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">config_load() </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> fetch()</td> </tr> </table> </div> </body> </html>