Getting Started with Smarty

Birdhouse offers the Smarty PHP templating engine for web application development. Note: Smarty is a tool for programmers, rather than for general end-users. If you’re a typical Dreamweaver user, Smarty is probably not the tool you’re looking for.

Birdhouse does not offer Smarty programming support — we’ve merely installed the Smarty classes for your use.

Here are brief instructions to help you get up and running with Smarty templates quickly.

Create a directory in your home, outside of your public_html, called “smarty.” Within this directory, create four directories:

templates
configs
templates_c
cache

Make the templates_c and cache directories writable by the web server:

chmod 777 templates_c cache

(If you want these directories to be more secure, ask Birdhouse to make them writable by Apache and you but by nobody else). In the smarty directory, create a file called smarty_main.inc with the following contents (replacing “username” with your username, of course):


<?php
/* Master include for  Smarty pages */

require('/usr/lib/php/Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = '/home/username/smarty/templates';
$smarty->compile_dir = '/home/username/smarty/templates_c';
$smarty->cache_dir = '/home/username/smarty/cache';
$smarty->config_dir = '/home/username/smarty/configs';
?>

You should now be able to begin Smarty development by including this at the top of each page of your Smarty application:


<?php
require_once('/home/username/smarty/smarty_main.inc');
?>

For more information, see documentation and examples at smarty.php.net.

Return to FAQs