SMARTY Info

Why Use SMARTY?
The SMARTY PHP template engine allows developers to easily separate the PHP back-end operations from the more design oriented code. What this means is your application has neat and separate PHP and HTML code, and that the look and feel of the site can be easily changed without messing with any of the code that makes the site tick or visa versa.

Introduction
SMARTY, while useful, does not write either HTML or PHP code for you. COMTOR uses XHTML 1.0 Transitional for markup. If you are unfamiliar with HTML/CSS or PHP you should refer to w3schools until you are proficient in XHTML, CSS, and PHP, before you begin using SMARTY.

Using SMARTY
When a PHP page is opened, even if SMARTY is installed on your server space, it is not necessarily using SMARTY. In order to initialize SMARTY you must have two lines of code.

The first line points the page to your SMARTY installation, and the second creates a new instance of SMARTY called $tpl.

In a PHP file using SMARTY there should be no HTML, formatting, or styling. The sole job of PHP is to gather the required information for the page then send it to a template file using SMARTY. You do this by saving your information as variables as you normally would in a strictly PHP file and then sending those variables to a SMARTY like so:

where  is an existing variable in the PHP code, and   is the instance of SMARTY you already created. will then be a variable in your SMARTY instance.

Once all your required variables have been sent to SMARTY you need to display a template which will use them.

where foobar.tpl is a file in your templates folder.

.tpl files are essentially HTML files, however they are able to use the variables you've sent to your SMARTY instance. They can also contain some basic programming functionality, but all this must be contained in curly brackets.

For example:

To create if statements and for loops you must similarly:

You can also assign variables within a .tpl file like this.

For more information on SMARTY refer to the SMARTY Documentation.