Smarty, a PHP templating system (http://www.smarty.net/)


How to separate programmers' code (PHP) from designers' code (HTML), or better phrased, how to separate the content from presentation. Smarty, a PHP templating system, was born to solve this problem.

The basic functionality of a templating system is introducing a way of separating presentation from content with very little interaction between programmers and designers.

With Smarty, the PHP syntax doesn't contain print. Instead, the programmer passes these arrays to
the designer by assigning them to Smarty templates. Then it's the designer's job to make them look
good in the web page without worrying about the PHP code. This is one big benefit about using
Smarty, and we will learn in this book how this is done.

The Smartness of Smarty
Smarty allows designers and programmers to interoperate more effectively and not worry about
each other's work. The designer builds the templates for the web page layout and extracts the data
from the PHP files that the programmer has created. The programmer passes data to the templates
without having to generate HTML code. This way, everyone is happy and more efficient because
they all do the job they are good at.

Let's think about an e-commerce site that sells laptop computers. The manufacturer's name, the
model number, characteristics, and price are content elements that will be stored in a database and
displayed to the visitor.

Smarty makes the job of the designer as well as the programmer very easy. The key tasks
performed by them can be listed as follows.

The Programmer's tasks:
•  Extract database elements with a simple query on the database.

•  Validate and manipulate the data by performing business logic on it.
 
•  If needed, change the data access methods and the business logic without interfering
with the designer's work. For example, the whole system could migrate from
MySQL to PostgreSQL without the designer making a single change.

The Designer's tasks:

•  Create HTML designs without affecting or jeopardizing the programmers PHP code.
The designer only needs to be concerned with placing the content elements that the
programmer has agreed to provide.

•  Make changes to the design without consulting or interfering with the
programmer's work.

•  Stop worrying  about technical changes to the site breaking the way that the site
appears to viewers.


0 comments:

Post a Comment