<HTML ><HEAD ><TITLE >{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="{literal}" HREF="language.function.literal.html"><LINK REL="NEXT" TITLE="{section},{sectionelse}" HREF="language.function.section.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.literal.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.section.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.function.php" ></A >{php}</H1 ><P > The <TT CLASS="varname" >{php}</TT > tags allow PHP code to be embedded directly into the template. They will not be escaped, regardless of the <A HREF="variable.php.handling.html" ><TT CLASS="parameter" ><I >$php_handling</I ></TT ></A > setting. This is for advanced users only, not normally needed and not recommended. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Technical Note: </B > To access PHP variables in <TT CLASS="varname" >{php}</TT > blocks you will need to use the PHP <A HREF="http://php.net/global" TARGET="_top" >global</A > keyword. </P ></BLOCKQUOTE ></DIV ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN2298" ></A ><P ><B >Example 7-28. Example php in {php} tags</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >{php} // including a php script directly from the template. include('/path/to/display_weather.php'); {/php}</PRE ></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="AEN2301" ></A ><P ><B >Example 7-29. {php} tags with global and assigning a variable</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> {* this template includes a {php} block that assign's the variable $varX *}<br />{php}<br /> global $foo, $bar;<br /> if($foo == $bar){<br /> echo 'This will be sent to browser';<br /> }<br /> // assign a variable to Smarty<br /> $this->assign('varX','Toffee');<br />{/php}<br />{* output the variable *}<br /><strong>{$varX}</strong> is my fav ice cream :-)</span> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="variable.php.handling.html" ><TT CLASS="parameter" ><I >$php_handling</I ></TT ></A >, <A HREF="language.function.include.php.html" ><TT CLASS="varname" >{include_php}</TT ></A >, <A HREF="language.function.include.html" ><TT CLASS="varname" >{include}</TT ></A >, <A HREF="language.function.insert.html" ><TT CLASS="varname" >{insert}</TT ></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.literal.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.section.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >{literal}</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" >{section},{sectionelse}</TD ></TR ></TABLE ></DIV ></BODY ></HTML >