Debug
Smarty comes with its own debugging console (see the image at right). To invoke the debugging console, set the $debugging variable to TRUE in your PHP code:
require('Smarty.class.php');
$page = new Smarty();
$page->debugging = TRUE;
The console pops up in a separate window (see the figure), showing the templates being used, the values of variables, and other useful information.
Math
Basic mathematical calculations can be done within Smarty templates:
Price: ${$price}
Qty: {$qty}
Total: ${$qty * $price}
Plugins
Smarty supports adding features through the creation of plugins. By writing your own plugin, you can make a new modifier or function. The details for creating your own plugin are discussed in the Smarty manual.
Obfuscating E-mail Addresses
The {mailto} plugin can be used to safeguard e-mail addresses. E-mail addresses can be harvested by spambots that read a page's HTML source and pull out anything that looks like an e-mail address. This plugin uses JavaScript to mask the address in the HTML source, while preserving it's appearance in the browser (see the image at right). Although spambots could theoretically still retrieve the e-mail address, this is safer than using no obfuscation at all.
{mailto address=$email encode='javascript' subject='Default Subject Line'}
Smarty Template Functions
In this tutorial you learned about how to use various PHP smarty template functions including email obfuscation, mathematical operators, debugging console, configuration, and more.
|