PHP Programming/Smarty templating system

What is Smarty?
is a templating engine for PHP. It allows you to separate logic and presentation by separating the PHP code from the HTML (or anything else for that matter) presentation.

Old/custom templating engine example
It is just like below: (The code below is a demo of a custom template engine - not Smarty)

There are two files here &quot;mail.html&quot; (we can say this is a template file) and &quot;mail_engine.php&quot; (ya, you are right...it is an engine.)



This example allows small functionality. You might have big problems if your company value contains #CITY#, for example. There are much more advantages of using smarty. But anyway, raw PHP templating is most effective and fastest.

How does it work?
Smarty is a template engine which actually compiles the template file to the php file that can be later executed. This simply saves time on parsing and variable outputs, beating other Template Engines with much smaller memory use and regex.

Installation
Installation is very basic and easy to use

There is no requirement to copy other files as they are simple examples.
 * 1) Download Smarty Source from smarty.net
 * 2) Open it using your archive extractor (must be compatible with .tar.gz files)
 * 3) Go to the directory called Smarty-x.x.x
 * 4) Copy the libs folder to your website's root ( where you want the website to exist, for example /My_Site/ )
 * 5) You are done!

Basic Syntax #2
Comments: {* Comment *} Writing a variable, assigned from the PHP script: {$variable} Writing a variable, assigned from the config file: Using a variable in a function: $variable Other Examples (Smarty Documentation): Many other combinations are allowed: Calling Functions: {function}
 * 1) variable#

Integrating into a website
To make use of the Smarty Template engine you will need to change your php script, which is used for controlling the Smarty engine and compile the template file. Simple example:

Arrays
Please refer to

Looping
Looping in smarty is just like PHP, except that there are different ways of approaching the variables. For example, in PHP you would write this:

As Smarty compiles similar piece of code by this:

Also, you can use a section function which is very similar to foreach

In the case the designer wanted to add bullet points, or indexes of the array items, there would be no need to do anything for the programmer as you can use other variables that would change themselves after each loop.

Conditions
{if} statements in Smarty have much the same flexibility as PHP if statements, with a few added features for the template engine. Every {if} must be paired with an {/if}. {else} and {elseif} are also permitted. All PHP conditionals are recognized, such as ||, or, &&, and, etc.

The following is a list of recognized qualifiers, which must be separated from surrounding elements by spaces. Note that items listed in [brackets] are optional. PHP equivalents are shown where applicable.