<HTML ><HEAD ><TITLE >{include_php}</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="Built-in Functions" HREF="language.builtin.functions.html"><LINK REL="PREVIOUS" TITLE="{include}" HREF="language.function.include.html"><LINK REL="NEXT" TITLE="{insert}" HREF="language.function.insert.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" 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="language.function.include.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 7. Built-in Functions</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.function.insert.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.function.include.php" ></A >{include_php}</H1 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Technical Note: </B > <TT CLASS="varname" >{include_php}</TT > is pretty much deprecated from Smarty, you can accomplish the same functionality via a custom template function. The only reason to use <TT CLASS="varname" >{include_php}</TT > is if you really have a need to quarantine the php function away from the <A HREF="variable.plugins.dir.html" ><TT CLASS="filename" >plugins/</TT ></A > directory or your application code. See the <A HREF="tips.componentized.templates.html" >componentized template example</A > for details. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="informaltable" ><A NAME="AEN2079" ></A ><P ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >Attribute Name</TH ><TH WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >Type</TH ><TH WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >Required</TH ><TH WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >Default</TH ><TH WIDTH="20%" ALIGN="LEFT" VALIGN="MIDDLE" >Description</TH ></TR ></THEAD ><TBODY ><TR ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >file</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >string</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >Yes</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >n/a</I ></SPAN ></TD ><TD WIDTH="20%" ALIGN="LEFT" VALIGN="MIDDLE" >The name of the php file to include</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >once</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >boolean</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >No</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" ><SPAN CLASS="emphasis" ><I CLASS="emphasis" ><TT CLASS="constant" >TRUE</TT ></I ></SPAN ></TD ><TD WIDTH="20%" ALIGN="LEFT" VALIGN="MIDDLE" >whether or not to include the php file more than once if included multiple times</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >assign</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >string</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" >No</TD ><TD WIDTH="20%" ALIGN="CENTER" VALIGN="MIDDLE" ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >n/a</I ></SPAN ></TD ><TD WIDTH="20%" ALIGN="LEFT" VALIGN="MIDDLE" >The name of the variable that the output of include_php will be assigned to</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ><P > <TT CLASS="varname" >{include_php}</TT > tags are used to include a php script in your template. If <A HREF="variable.security.html" ><TT CLASS="parameter" ><I >$security</I ></TT ></A > is enabled, then the php script must be located in the <A HREF="variable.trusted.dir.html" ><TT CLASS="parameter" ><I >$trusted_dir</I ></TT ></A > path. The <TT CLASS="varname" >{include_php}</TT > tag must have the attribute <TT CLASS="parameter" ><I >file</I ></TT >, which contains the path to the included php file, either relative to <A HREF="variable.trusted.dir.html" ><TT CLASS="parameter" ><I >$trusted_dir</I ></TT ></A >, or an absolute path. </P ><P > By default, php files are only included once even if called multiple times in the template. You can specify that it should be included every time with the <TT CLASS="parameter" ><I >once</I ></TT > attribute. Setting once to <TT CLASS="constant" >FALSE</TT > will include the php script each time it is included in the template. </P ><P > You can optionally pass the <TT CLASS="parameter" ><I >assign</I ></TT > attribute, which will specify a template variable name that the output of <TT CLASS="varname" >{include_php}</TT > will be assigned to instead of displayed. </P ><P > The smarty object is available as <TT CLASS="parameter" ><I >$this</I ></TT > within the PHP script that you include. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN2134" ></A ><P ><B >Example 7-21. function {include_php}</B ></P ><P >The <TT CLASS="filename" >load_nav.php</TT > template.</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">// load in variables from a mysql db and assign them to the template<br /></span><span style="color: #007700">require_once(</span><span style="color: #DD0000">'MySQL.class.php'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sql </span><span style="color: #007700">= new </span><span style="color: #0000BB">MySQL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$sql</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">'select * from site_nav_sections order by name'</span><span style="color: #007700">,</span><span style="color: #0000BB">SQL_ALL</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">assign</span><span style="color: #007700">(</span><span style="color: #DD0000">'sections'</span><span style="color: #007700">,</span><span style="color: #0000BB">$sql</span><span style="color: #007700">-></span><span style="color: #0000BB">record</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ><P > Where the teamplate is: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >{* absolute path, or relative to $trusted_dir *} {include_php file='/path/to/load_nav.php'} {foreach item='curr_section' from=$sections} <a href="{$curr_section.url}">{$curr_section.name}</a><br /> {/foreach}</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="language.function.include.html" ><TT CLASS="varname" >{include}</TT ></A >, <A HREF="language.function.php.html" ><TT CLASS="varname" >{php}</TT ></A >, <A HREF="language.builtin.functions.html#language.function.capture" ><TT CLASS="varname" >{capture}</TT ></A >, <A HREF="template.resources.html" >template resources</A > and <A HREF="tips.componentized.templates.html" >componentized templates</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="language.function.include.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="language.function.insert.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >{include}</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="language.builtin.functions.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >{insert}</TD ></TR ></TABLE ></DIV ></BODY ></HTML >