Overview
KB
Learn PHP
PHP techniques
PHP Smarty Functions
PHP Web Email
Secure development
PHP Security Scenario
SSH and SFTP
PHP Smarty
PHP Smarty Modifiers
PHP Smarty Caching
PHP Smarty Misc
CakePHP
Zend Framework
PHP basics

PHP Smarty

Smarty Basics

Smarty uses the curly brackets--{ and }--to delineate special code. Anything on a template page between the curly brackets will be handled by Smarty. Anything outside of those is treated literally. Smarty also has its own style of comments--{* and *}. Anything within those will have no effect and will not be sent in the HTML source code. This allows you to place comments within a template that are not viewable in a Web browser (unlike HTML comments). These same delineators can be used for multiline comments, as well. Variables in a template have the same naming conventions as those in PHP code, although they have to be within the curly brackets to be meaningful to Smarty. For example: {$var}. Numerical-indexed array elements can be accessed using $array[3]. Associative array elements can be accessed using $array.key or $array['key']. As in PHP, variables in Smarty are case-sensitive. Smarty has two types of special variables: configuration variables and $smarty. Configuration variables in a template are surrounded by hashmarks: #var#. The placeholder will be replaced with the corresponding value from a configuration file. $smarty is a special variable, providing a way to access configuration variables, $_GET, $_POST, $_COOKIE, $_SESSION, etc., and a couple of other useful values. Smarty supports many other features, each of which is discussed on its own page of this PHP Tutorial:
Modifiers
Modifiers are used in templates to provide default modifications of placeholder values. Examples include changing a string's case, formating a date, or applying the nl2br() function.
Functions
Functions allow you to add logic to presentations by including files, looping through arrays, using conditionals, and so forth.
Caching
By applying caching to templated pages, you can improve a site's performance.
Miscellaneous
A few remaining topics are discussed here, including: the $smarty reserved variable, configuration files, debugging, plugins, math, and obfuscating e-mail addresses.

Article continues:  <<previous page

 Download NuSphere PHP IDE

Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.

 Buy NuSphere PhpED® now

Best PHP Editor and complete PHP IDE.
NuSphere PhpED 21.0 is available from our online store front.

 Special Team4 Offer

Get 4 copies of PhpED for the price of 3!

Optimum solution for development teams.
PhpED 21.0 Team4
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.
"To be honest its bloody awesome, I have looked at loads of PHP editors and this is THE only one that actual works straight out of the box!!! Brilliant, well done."
Andrew Breward,
Director of Technology
caboodal.com