Get Smarty


Donate Bitcoin Bitcoin

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping -

Brautkleider auf

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Find Wedding Dresses Online at Canada from

Cheap bridesmaid dresses - rush delivery only 10 days delivery to Australia at

where cheap prom dresses uk at


Extended Setup

This is a continuation of the basic installation, please read that first!

A slightly more flexible way to setup Smarty is to extend the class and initialize your Smarty environment. So instead of repeatedly setting directory paths, assigning the same vars, etc., we can do that in one place.

Lets create a new directory /php/includes/guestbook/ and make a new file called setup.php. In our example environment, /php/includes is in our include_path. Be sure you set this up too, or use absolute file paths.

Example 2.10. /php/includes/guestbook/setup.php


// load Smarty library

// The setup.php file is a good place to load
// required application library files, and you
// can do that right here. An example:
// require('guestbook/guestbook.lib.php');

class Smarty_GuestBook extends Smarty {

   function Smarty_GuestBook()

        // Class Constructor.
        // These automatically get set with each new instance.


        $this->template_dir = '/web/';
        $this->compile_dir  = '/web/';
        $this->config_dir   = '/web/';
        $this->cache_dir    = '/web/';

        $this->caching = true;
        $this->assign('app_name', 'Guest Book');



Now lets alter the index.php file to use setup.php:

Example 2.11. /web/



$smarty = new Smarty_GuestBook();




Now you see it is quite simple to bring up an instance of Smarty, just use Smarty_GuestBook() which automatically initializes everything for our application.

No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 9 plus 19? (Are you human?)