O'Reilly logo

PHP and Smarty on Large-Scale Web Development by Vitor Rodrigues, Bruno Pedro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 the assign() 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required