# PHP Programming/Smarty templating system
## What is Smarty?

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 "mail.html" (we can say this is a template file) and "mail_engine.php" (ya, you are right...it is an engine.)

### mail_engine.php

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

## Usage
### Basic Syntax
### Basic Syntax #2

Comments:
Writing a variable, assigned from the PHP script:
Writing a variable, assigned from the config file:
Using a variable in a function:
Other Examples (Smarty Documentation):
Many other combinations are allowed:
Calling Functions:

### 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:

### Variables

#Basic Syntax #2

### Arrays

Please refer to #Variables

## 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.
| Qualifier | Alternates | Syntax Example | Meaning | PHP Equivalent |
| == | eq | $a eq $b | equals | == |
| != | ne, neq | $a neq $b | not equals | != |
| > | gt | $a gt $b | greater than | > |
| < | lt | $a lt $b | less than | < |
| >= | gte, ge | $a ge $b | greater than or equal | >= |
| <= | lte, le | $a le $b | less than or equal | <= |
| === | | $a === 0 | check for identity | === |
| ! | not | not $a | negation (unary) | ! |
| % | mod | $a mod $b | modulous | % |
| is [not] div by | | $a is not div by 4 | divisible by | $a % $b == 0 |
| is [not] even | | $a is not even | [not] an even number (unary) | $a % 2 == 0 |
| is [not] even by | | $a is not even by $b | grouping level [not] even | ($a / $b) % 2 == 0 |
| is [not] odd | | $a is not odd | [not] an odd number (unary) | $a % 2 != 0 |
| is [not] odd by | | $a is not odd by $b | [not] an odd grouping | ($a / $b) % 2 != 0 |

## References

* ↑ Smarty Website, Documentation, Downloads