Smarty for Web Designers
Now that you've seen all the technical details about PHP and Smarty configuration, it's time to show you the other side of Smarty.
Smarty's biggest advantage is its ease of use among web designers. In the following sections, we teach you how to use developed functionalities on your Smarty templates.
Crash Course
Next, we'll help you start using Smarty's main features. For a more complete reference, take a look at the Smarty documentation for web designers.[†]
Also, remember that you should first have a working Smarty environment, as explained previously.
Using variables
Variables are a way to store values and later perform some action on them. You can, for instance, store the name of the user and display it on a specific web page. Variables can be assigned from within PHP, loaded from configuration files, and manipulated directly in Smarty.
Let's see how you can assign variables in these three ways:
- PHP assigned variables
These variables are used with a preceding dollar sign (
$
), like you''d do in PHP itself. They are assigned through theassign()
method of the Smarty class. Variables can be scalars, associative or indexed arrays, or even object properties.- Variables created from within Smarty templates
You can also assign values to variables by using the Smarty
{assign}
custom function. Variables created by this method are only available within the template where the variable was created.- Variables loaded from configuration files
Configuration variables must be enclosed ...
Get PHP and Smarty on Large-Scale Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.