Installing Smarty

Sep 24, 2009 Author: Dr_ViRuS

Follow these steps to install Smarty on your server. Create a directory on your server within the web root named smarty to store the core Smarty files.

  • Go to and download the latest version of Smarty. Decompress and extract it to a folder on your computer.
  • Transfer all Smarty files from your computer to the smarty directory on your server.
  • On your server, create another directory called templates for your Smarty templates. Create two subdirectories here: html for the raw templates and compile for Smarty-compiled templates.
  • Make the compile directory writeable by the webserver.
  • In the templates directory, create (or upload) a file called smarty_initialize.php, containing the following:
define ("SMARTY_DIR", "/path/to/web/root/smarty/");
require_once (SMARTY_DIR."Smarty.class.php");
$smarty = new Smarty;
$smarty->compile_dir = "/path/to/web/root/templates/compile";
$smarty->template_dir = "/path/to/web/root/templates/html"; 

Four aspects of the smarty_initialize.php file are very important:

  • The SMARTY_DIR constant points at the Smarty library directory.
  • To load the library, smarty_initialize.php requires the Smarty.class.php file.
  • Because Smarty is object-oriented, you must create a new Smarty object. This script does so with $smarty = new Smarty.
  • Smarty needs to know where your template and compile directories

views 5129
  1. Add New Comment