Smarty supports its own functions, called smarty template functions.
Using Smarty PHP Functions
To call a Smarty function, place the function name within the Smarty tags:
{function_name}
Smarty has both built-in and custom functions. Many of the built-in functions provide logical structures, like conditionals and loops.
Function Attributes
To pass values to the function when calling it, follow the function name with name="value" pairs:
{function_name name1="some value" name2="some other value"}
If the value of an attribute should be a variable, do not quote it:
{function_name name1=$var name2="some other value"}
As with PHP, variables can be put within double quotation marks:
{include file="$filename.tpl"}
Single quotes in that example would not work.
Including Other Files
Smarty supports the ability to include templates within templates. Most commonly this would be used when a site has standard header, footer, navigation, and other elements. The "include" function can include another template within the current template. It's first argument is the name of the file to be included:
{include file='filename.tpl'}
By passing the include function an attribute matching a variable within the included template, you can pass variables:
{include file='filename.tpl' var_name='some value'}
{* filename.tpl *}
Something: $var_name
Similar to "include" is "insert", which creates a non-cached section of a template. This is discussed on the Smarty Caching page.
|