Pages

Sunday, 13 January 2013

How to Install Smarty on Windows

Installing Smarty on Windows

This document assumes that you have configured PHP5, Apache Webserver already.
  1. Download Smarty
  2. Unzip the content of Smarty zip file to smarty folder. So it appears as  C:/server/smarty
  3. Create two folders templates_c  and cache inside it. So it appears as C:/server/smarty/templates_c and C:/server/smarty/cache
  4. Browse to PHP Installation Directory and edit php.ini's include_path and add the location of the libs folder. Example: include_path = ".;C:/server/smarty/libs/;"
  5. Restart IIS/Apache
  6. Create a new folder in htdocs (root) folder and rename it to smarty. C:\server\htdocs\smarty
  7. Create two folders configs and templates inside it. C:\server\htdocs\smarty\configs and C:\server\htdocs\smarty \templates
  8. Smarty configuration is done. Create two scripts index.php and index.tpl to test Smarty template engine.
  9. Place index.php inside C:\server\htdocs\smarty and index.tpl inside C:\server\htdocs\smarty \templates
  10. Open the web browser and type in the URL http://localhost/smarty.

index.php

<?php

// load Smarty library

require('Smarty.class.php');

$smarty = new Smarty;

$smarty->template_dir = ‘C:\server\htdocs\smarty \templates’;

$smarty->conf ig_dir = ‘C:\server\htdocs\smarty\configs’;

$smarty->cache_dir = ‘C:/server/smarty/cache’;

$smarty->compile_dir = ' C:/server/smarty/templates_c’;

$smarty->assign('name','Lucky!!');

$smarty->display('index.tpl');

?>

index.tpl

<html>

<body>

Hello, {$name}

<body>

<html>