Archive for the ‘Smarty’ Category

Smarty template engine

April 2, 2008

Smarty is a template engine for PHP. More specifically, it facilitates a manageable way to separate application logic and content from its presentation.
Benefits of using Smarty template engines:
1. separates code from HTML.
2. When you get used to using template engines, your applications will be developed faster
3. Your source code will be more organized, more clean and easier to understand
4. Teamwork is a lot easier.
Web page designers are not dealing with PHP code syntax, but instead easy-to-use templating syntax not much different than plain HTML. The templates are a very close representation of the final output, dramatically shortening the design cycle.

Code example

Since Smarty separates PHP from HTML, you have two files:

Follow the steps:
1.Download Latest Stable Release Smarty here
2. create two directory in www or htdoces named templates and temp
3. create a html file named test.html in templates dir
4. create a php file named test.php in root dir(i.e,www/htdocs)
step 2:
paste the following codes in test.html file

step 3:
paste the following codes in test.php file

Now browse test.php
output of this script will be…
This is the Smarty basic example.