Get Smarty


Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping -

Shop for 2018 World Cup Football Boots Online sale at

Browse best 2018 world cup soccer cleats and shoes from


{$smarty} reserved variable

The PHP reserved {$smarty} variable can be used to access several environment and request variables. The full list of them follows.

Request variables

The request variables such as $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV and $_SESSION can be accessed as demonstrated in the examples below:

Example 4.8. Displaying request variables

{* display value of page from URL ($_GET) *}

{* display the variable "page" from a form ($_POST['page']) *}

{* display the value of the cookie "username" ($_COOKIE['username']) *}

{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}

{* display the system environment variable "PATH" *}

{* display the php session variable "id" ($_SESSION['id']) *}

{* display the variable "username" from merged get/post/cookies/server/env *}



For historical reasons {$SCRIPT_NAME} is short-hand for {$smarty.server.SCRIPT_NAME}.

<a href="{$SCRIPT_NAME}?page=smarty">click me</a>
<a href="{$smarty.server.SCRIPT_NAME}?page=smarty">click me</a>


Although Smarty provides direct access to PHP super globals for convenience, it should be used with caution. Directly accessing super globals mixes underlying application code structure with templates. A good practice is to assign specific needed values to template vars.


The current timestamp can be accessed with {$}. The value reflects the number of seconds passed since the so-called Epoch on January 1, 1970, and can be passed directly to the date_format modifier for display. Note that time() is called on each invocation; eg a script that takes three seconds to execute with a call to $ at start and end will show the three second difference.

{* use the date_format modifier to show current date and time *}
{$|date_format:'%Y-%m-%d %H:%M:%S'}



You can access PHP constant values directly. See also smarty constants.

// the constant defined in php

Output the constant in a template with



Although Smarty provides direct access to PHP constants for convenience, it is typically avoided as this is mixing underlying application code structure into the templates. A good practice is to assign specific needed values to template vars.


Template output captured via the built-in {capture}..{/capture} function can be accessed using the {$smarty.capture} variable. See the {capture} page for more information.


{$smarty.config} variable can be used to refer to loaded config variables. {$} is a synonym for {#foo#}. See the {config_load} page for more info.


The {$smarty.section} variables can be used to refer to {section} loop properties. These have some very useful values such as .first, .index, etc.


The {$smarty.foreach} variable is no longer used with the new {foreach} syntax, but is still supported with Smarty 2.x style foreach syntax.


Returns the name of the current template being processed (without the directory).


Returns the template object of the current template being processed.


Returns the name of the directory for the current template being processed.


Returns the version of Smarty the template was compiled with.

<div id="footer">Powered by Smarty {$smarty.version}</div>


Returns block text from child template. See Template interitance.


Returns block text from parent template. See Template interitance

{$smarty.ldelim}, {$smarty.rdelim}

These variables are used for printing the left-delimiter and right-delimiter value literally, the same as {ldelim},{rdelim}.

See also assigned variables and config variables

No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 12 plus 6? (Are you human?)