Smarty installation steps on WAMP and XAMPP

This document assumes that your webserver and php5 is running.
1 Download Smarty - http://smarty.php.net
2 Installation – Windows, IIS/Apache, PHP5
3 Extract files, rename Smarty.x.x.x to smarty (suggest OUTSIDE of your www root!)
Example: d:\smarty
4 Run phpinfo.php to find out your php.ini location
5 Edit php.ini’s include_path and add the location of the libs folder.
example: include_path = “.;d:\smarty\libs”
6 Restart IIS/Apache
7 Setup these two folders INSIDE your www root:
(wwwroot)/smarty/templates (this is where your templates will go)
(wwwroot)/smarty/configs
8 Setup these two folders OUTSIDE of your www root:
d:/smarty/templates_c
d:/smarty/cache
9 Setup security settings for the webserver to write to these four folders

<span style="font-weight:bold;">Example </span>
In (wwwroot) create index.php and in (wwwroot)/smarty/templates/index.tpl with the following code:
<?php

// load Smarty library
require(’Smarty.class.php’);

$smarty = new Smarty;

$smarty->template_dir = ‘d:/inetpub/wwwroot/smarty/templates’;
$smarty->config_dir = ‘ d:/inetpub/wwwroot/smarty/config’;
$smarty->cache_dir = ‘d:/smarty/smarty_cache’;
$smarty->compile_dir = ‘d:/smarty/smarty_templates_c’;

$smarty->assign(’name’,'fish boy!’);

$smarty->display(’index.tpl’);
?>


index.tpl


<html>
<body>
Hello, {$name}!
</body>
</html>

Now open index.php in your web browser (requested from your webserver)

http://webserver/index.php

You can work this out to a referenced script/class:
smarty_connect.php:
<?php

// load Smarty library
require(’Smarty.class.php’);

class smarty_connect extends Smarty
{
function smarty_connect()
{
// Class Constructor.
// These automatically get set with each new instance.

$this->Smarty();

$this->template_dir = ‘ d:/inetpub/wwwroot/smarty/templates’;
$this->config_dir = ‘ d:/inetpub/wwwroot/smarty/config’;
$this->compile_dir = ‘d:/smarty/templates_c’;
$this->cache_dir = ‘d:/smarty/cache’;

$this->assign(’app_name’, ‘Intranet’);
}
}
?>

index.php:
<?php

require(’smarty_connect.php’);

$smarty = new smarty_connect;

$smarty->assign(’name’,'Ned’);

$smarty->display(’index.tpl’);
?>

index.tpl:
<html>
<body>
Hello, {$name}!
</body>
</html>

Comments

  1. Hi,
    When I use smarty_connect.class.php then I could not able to access index.tpl file.
    Why? I dont know.
    It gives me an error like
    Smarty error: unable to read resource: "index.tpl" in C:\wamp\smarty\libs\Smarty.class.php on line 1093

    ReplyDelete
  2. Hi,
    Would you renamed the smarty.class.php to smarty_connect.class.php, if so please rename it as smarty.class.php because a class has been written in the name called smarty and the constructors in that class would reffer to the same class name. so it better to use smarty instead of smarty_connect.

    ReplyDelete

Post a Comment

Popular posts from this blog

How To Install XAMPP in Support with PostgreSQL And phpPgAdmin

Recession Does Not Affect Website Development and it is mainly possible through open source technology like LAMP Stack