PHP Programmer’s Of Bangladesh

SMARTY: Template Engine

Posted by: Md. Masud on: May 3, 2007

First copy the downloaded smarty folder into your project root directory. Then goto that smarty folder, create a php file (ex: smarty.php) & paste these following codes:

<?php

/* This is a class defination for accessing smarty. */ require(“C:/apache2triad/htdocs/project/smarty/libs/Smarty.class.php”);

class Template extends Smarty {
function Template() {
$this->Smarty();
//setting up smarty template directory
$this->template_dir=’c:/apache2triad/htdocs/project/templates/’;
//setting up smarty template directory
$this->compile_dir=’c:/apache2triad/htdocs/project/templates_c/’;
//setting up smarty configs directory
$this->config_dir=’c:/apache2triad/htdocs/project/configs/’;
//setting up smarty cache directory
$this->cache_dir=’c:/apache2triad/htdocs/project/cache/’;
$this->caching=false;
// defining application name
$this->assign(‘app_name’,'project’);
}
}
?>

Remember i used apache2triad for local testing. If u have different path, pls do change your path according to it. After copy pasting the codes into the php, save it & return to your project root. Include this (smarty.php) file to all of your php’s or u can create a config file for your project to include the smarty class. Now create 4 folders named as:

1. templates (ex: c:/apache2triad/htdocs/project/templates/ )
2. templates_c (ex: c:/apache2triad/htdocs/project/templates_c/ )
3. configs (ex: c:/apache2triad/htdocs/project/configs/ )
4. cache (ex: c:/apache2triad/htdocs/project/cache/ )

Now initiate Smarty object in your php file as

$template = new Template();
//example of assigning php variable to smarty
$template->assign(‘variable’, $var);
//example of displaying the template
$template->display(‘index.html’);

Remember to put all of your template files under the project root’s template directory:

(Ex: c:/apache2triad/htdocs/project/templates/index.html)

To Know more about Smarty visit the following link:
SMARTY MANUAL
Smarty Example

If Anyone need smarty book, just mention here. we will try our best to provide u that.

with regards
masud
Configuration provided by: Yamin Noor (ymnoor21@gmail.com)

5 Responses to "SMARTY: Template Engine"

it is very useful i learned a lot and provide full information regarding how to compile amnd what to store in template_c and remaining files

I have been looking for sites like this for a long time. Thank you!

Pretty nice site, wants to see much more on it! :)

I do, I do, I do need it..

Same here, need a decent book on smarty, i am well confused as some things are working right up to the point of extending smartys setup.

It took ages to sort out my include path in my php.ini – a search for it showed four different locations of it on my system :-/

Much obliged though, Tdf.

Leave a Reply

Where I was???

I was a PHP/MySQL web application developer in EVOKNOW INC from 1st July, 2006 to 5th Nov, 2007.

Blog Stats

  • 27,587 hits

What is the date?????

May 2007
S S M T W T F
« Apr   Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

My Links in Del.icio.us

Google Adds