Smarty has several different types of variables, all of which are explained in more detail below. The type of the variable depends on what symbol it is prefixed with (or enclosed within).
Variable in Smarty can be either displayed directly or used as arguments for function attributes and modifiers, inside conditional expressions, etc. To print a variable, simply enclose it in the delimiters so that it is the only thing contained between them. Examples:
{$Name} {$Contacts[row].Phone} <body bgcolr="{#bgcolor#}"> |
Variables that are assigned from PHP are referenced by preceding them with a dollar sign $.
You can also reference associative array variables that are assigned from PHP by specifying the key after the '.' (period) symbol.
Example 3-5. accessing associative array variables
|
Properties of objects assigned from PHP can be referenced by specifying the property name after the '->' symbol.
Example 3-7. accessing object properties
|
Variables that are loaded from the config files are referenced by enclosing them within hash marks (#).
Config file variables cannot be used until after they are loaded in from a config file. This procedure is explained later in this document under config_load.
The reserved {$smarty} variable can be used to access several special template variables. The full list of them follows.
The request variables such as get, post, cookies, server, environment, and session variables can be accessed as demonstrated in the examples below:
The current timestamp can be accessed with {$smarty.now}. The number reflects the number of seconds passed since the so-called Epoch (January 1, 1970) and can be passed directly to date_format modifier for display purposes.
The output captured via {capture}..{/capture} construct can be accessed using {$smarty} variable. See section on capture for an example.
{$smarty} variable can be used to refer to 'section' and 'foreach' loop properties. See docs for section and foreach.