Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

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

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy wedding dresses on SiteSteer.com - Best Online Wedding Dress Store

Candy Crush Cheats

Tired of playing games? Visit the Game Supply to Sell World of Warcraft Accounts.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

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

{$smarty} reserved variable

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

Request variables

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

Example 4.7. Displaying request variables


{* 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}

   

Note

For historical reasons {$SCRIPT_NAME} can be accessed directly, although {$smarty.server.SCRIPT_NAME} is the proposed way to access this value.


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

{$smarty.now}

The current timestamp can be accessed with {$smarty.now}. 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 $smarty.now at start and end will show the three second difference.


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

   

{$smarty.const}

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


<?php
// the constant defined in php
define('MY_CONST_VAL','CHERRIES');
?>

Output the constant in a template with


{$smarty.const.MY_CONST_VAL}

{$smarty.capture}

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}

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

{$smarty.section}, {$smarty.foreach}

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

{$smarty.template}

Returns the name of the current template being processed. The following example shows the container.tpl and the included banner.tpl with {$smarty.template} within both.


<b>Main container is {$smarty.template}</b>
{include file='banner.tpl'}

will output


<b>Main page is container.tpl</b>
banner.tpl

{$smarty.version}

Returns the version of Smarty the template was compiled with.


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

{$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

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

Sponsors [info]

UK Web Hosting @webhost.uk.net
Best Web Hosting @rshosting.com
Web Hosting UK @webhostinguk.com
Unlimited Web Hosting @infrenion.com
App Entwicklung @morphodo.com
Buy from China @dhgate.com
dissertationteam.com
Buy Web Hosting @buy-hosting.net
WordPress Hosting Hub @wphostinghub.net