<HTML ><HEAD ><TITLE >{$smarty} reserved variable</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="Variables" HREF="language.variables.html"><LINK REL="PREVIOUS" TITLE="Variables loaded from config files" HREF="language.config.variables.html"><LINK REL="NEXT" TITLE="Variable Modifiers" HREF="language.modifiers.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.config.variables.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 4. Variables</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.modifiers.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.variables.smarty" ></A >{$smarty} reserved variable</H1 ><P > The PHP reserved <TT CLASS="parameter" ><I >{$smarty}</I ></TT > variable can be used to access several enviroment and request variables. The full list of them follows. </P ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.request" ></A >Request variables</H2 ><P > The <A HREF="http://php.net/reserved.variables" TARGET="_top" >request variables </A > such as <TT CLASS="literal" >$_GET</TT >, <TT CLASS="literal" >$_POST</TT >, <TT CLASS="literal" >$_COOKIE</TT >, <TT CLASS="literal" >$_SERVER</TT >, <TT CLASS="literal" >$_ENV</TT > and <TT CLASS="literal" >$_SESSION</TT > (see <A HREF="variable.request.vars.order.html" > <TT CLASS="varname" >$request_vars_order</TT ></A > and <A HREF="variable.request.use.auto.globals.html" > <TT CLASS="varname" >$request_use_auto_globals</TT ></A >) can be accessed as demonstrated in the examples below: </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN460" ></A ><P ><B >Example 4-7. Displaying request variables</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *} {$smarty.get.page} {* display the variable "page" from a form ($_POST['page']) *} {$smarty.post.page} {* display the value of the cookie "username" ($_COOKIE['username']) *} {$smarty.cookies.username} {* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*} {$smarty.server.SERVER_NAME} {* display the system environment variable "PATH" *} {$smarty.env.PATH} {* display the php session variable "id" ($_SESSION['id']) *} {$smarty.session.id} {* display the variable "username" from merged get/post/cookies/server/env *} {$smarty.request.username}</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > For historical reasons <TT CLASS="parameter" ><I >{$SCRIPT_NAME}</I ></TT > can be accessed directly, although <TT CLASS="parameter" ><I >{$smarty.server.SCRIPT_NAME}</I ></TT > is the proposed way to access this value. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><a href="{$SCRIPT_NAME}?page=smarty">click me</a> <a href="{$smarty.server.SCRIPT_NAME}?page=smarty">click me</a></PRE ></TD ></TR ></TABLE ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.now" ></A >{$smarty.now}</H2 ><P > The current <A HREF="http://php.net/function.time" TARGET="_top" >timestamp</A > can be accessed with <TT CLASS="parameter" ><I >{$smarty.now}</I ></TT >. The value reflects the number of seconds passed since the so-called Epoch on January 1, 1970, and can be passed directly to the <A HREF="language.modifier.date.format.html" ><TT CLASS="varname" >date_format</TT > </A > modifier for display. Note that <A HREF="http://php.net/function.time" TARGET="_top" ><TT CLASS="varname" >time()</TT ></A > is called on each invocation; eg a script that takes three seconds to execute with a call to <TT CLASS="parameter" ><I >$smarty.now</I ></TT > at start and end will show the three second difference. <DIV CLASS="informalexample" ><A NAME="AEN478" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >{* use the date_format modifier to show current date and time *} {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.const" ></A >{$smarty.const}</H2 ><P > You can access PHP constant values directly. See also <A HREF="smarty.constants.html" >smarty constants</A >. </P ><DIV CLASS="informalexample" ><A NAME="AEN484" ></A ><P ></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">// the constant defined in php<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'MY_CONST_VAL'</span><span style="color: #007700">,</span><span style="color: #DD0000">'CHERRIES'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ><P ></P ></DIV ><P >Output the constant in a template with</P ><DIV CLASS="informalexample" ><A NAME="AEN487" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >{$smarty.const.MY_CONST_VAL}</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.capture" ></A >{$smarty.capture}</H2 ><P > Template output captured via the built-in <A HREF="language.builtin.functions.html#language.function.capture" > <TT CLASS="varname" >{capture}..{/capture}</TT ></A > function can be accessed using the <TT CLASS="parameter" ><I >{$smarty.capture}</I ></TT > variable. See the <A HREF="language.builtin.functions.html#language.function.capture" > <TT CLASS="varname" >{capture}</TT ></A > page for more information. </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.config" ></A >{$smarty.config}</H2 ><P > <TT CLASS="parameter" ><I >{$smarty.config}</I ></TT > variable can be used to refer to loaded <A HREF="language.config.variables.html" >config variables</A >. <TT CLASS="parameter" ><I >{$smarty.config.foo}</I ></TT > is a synonym for <TT CLASS="parameter" ><I >{#foo#}</I ></TT >. See the <A HREF="language.function.config.load.html" >{config_load}</A > page for more info. </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.loops" ></A >{$smarty.section}, {$smarty.foreach}</H2 ><P > The <TT CLASS="parameter" ><I >{$smarty.section}</I ></TT > and <TT CLASS="parameter" ><I >{$smarty.foreach}</I ></TT > variables can be used to refer to <A HREF="language.function.section.html" ><TT CLASS="varname" >{section}</TT ></A > and <A HREF="language.function.foreach.html" ><TT CLASS="varname" >{foreach}</TT ></A > loop properties respectfully. These have some very useful values such as <TT CLASS="varname" >.first</TT >, <TT CLASS="varname" >.index</TT >, etc. </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.template" ></A >{$smarty.template}</H2 ><P > Returns the name of the current template being processed. The following example shows the <TT CLASS="filename" >container.tpl</TT > and the <TT CLASS="filename" >included banner.tpl</TT > with <TT CLASS="parameter" ><I >{$smarty.template}</I ></TT > within both. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><b>Main container is {$smarty.template}</b> {include file='banner.tpl}</PRE ></TD ></TR ></TABLE ><P > will output </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><b>Main page is container.tpl</b> banner.tpl</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.version" ></A >{$smarty.version}</H2 ><P > Returns the version of Smarty the template was compiled with. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><div id="footer">Powered by Smarty {$smarty.version}</div></PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="language.variables.smarty.ldelim" ></A >{$smarty.ldelim}, {$smarty.rdelim}</H2 ><P > These variables are used for printing the left-delimiter and right-delimiter value literally, the same as <A HREF="language.function.ldelim.html" > <TT CLASS="varname" >{ldelim},{rdelim}</TT ></A >. </P ><P > See also <A HREF="language.variables.html#language.assigned.variables" >assigned variables</A > and <A HREF="language.config.variables.html" >config variables</A > </P ></DIV ></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.config.variables.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.modifiers.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Variables loaded from config files</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="language.variables.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Variable Modifiers</TD ></TR ></TABLE ></DIV ></BODY ></HTML >