Smarty and XAMPP configuration on Windows

Smarty is a web template engine for PHP. It is helpful for web project that are performs by different people(e.g. programmer and designer). Smarty separates PHP from HTML, application logic and content from its presentation.


Configuration:

1. Download the latest XAMPP version from http://www.apachefriends.org/

2. Install at C: directory. (C:\xampp)

3. Create a new folder in xampp folder and rename it to smarty. (C:\xampp\smarty)

4. Download the latest Smarty version from http://www.smarty.net/

5. Unzip the content of Smarty zip file to smarty folder. (C:\xampp\smarty)

6. Create two folders templates_c and cache inside it. (C:\xampp\smarty\templates_c and C:\xampp\smarty\cache)

7. Open php.ini file (C:\xampp\php\php.ini), search for Paths and Directories. At Windows part, replace the line

    include_path = ".;C:\xampp\php\pear\"
    with
    include_path = ".;C:\xampp\php\pear\;C:\xampp\smarty\libs\"

8. Create a new folder in htdocs folder and rename it to smarty. (C:\xampp\htdocs\smarty)

9. Create two folders configs and templates inside it. (C:\xampp\htdocs\smarty\configs and C:\xampp\htdocs\smarty\templates)

10. Smarty configuration is done. Create two scripts index.php and index.tpl to test Smarty template engine.

11. Place index.php inside C:\xampp\htdocs\smarty\ and index.tpl inside C:\xampp\htdocs\smarty\templates\

    index.php
    <?php
    // load Smarty library
    require('Smarty.class.php');
    $smarty = new Smarty;
    $smarty-»template_dir = 'C:/xampp/htdocs/smarty/templates';
    $smarty-»config_dir = 'C:/xampp/htdocs/smarty/config';
    $smarty-»cache_dir = 'C:/xampp/smarty/cache';
    $smarty-»compile_dir = 'C:/xampp/smarty/templates_c';
    $smarty-»assign('name','Penguin !!');
    $smarty-»display('index.tpl');
    ?>
    index.tpl
    <html>
    <body>
    Hello, {$name}
    <body>
    <html>

12. Open the web browser and type in the URL http://localhost/smarty



Documentation: http://www.smarty.net/docs.php
Reference: http://news.php.net/php.smarty.dev/2703


52 comments:

Anonymous said... / December 21, 2009 8:04 PM  

didnt work for me, getting this error code


Parse error: parse error in C:\xampp\htdocs\index.php on line 5

Anonymous said... / February 18, 2010 8:38 PM  

same :'(

Anonymous said... / April 22, 2010 4:09 PM  

Is not work,any body know to solve this problem

hamzah said... / April 22, 2010 4:16 PM  

gak jalan d komputer saya...apakah ada solusi....problemnya juga sama

hamzah said... / April 22, 2010 5:22 PM  

7. Open php.ini file (C:\xampp\php\php.ini), search for Paths and Directories. At Windows part, replace the line

====
7. Open php.ini file (C:\xampp\apache\bin\php.ini)

Anonymous said... / May 10, 2010 8:47 PM  

it works, thanks

Anonymous said... / July 13, 2010 4:17 AM  

Change ->> for ->
----------------------
$smarty->template_dir = 'C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = 'C:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';
$smarty->assign('name','Penguin !!');
$smarty-»display('index.tpl');

Anonymous said... / July 15, 2010 7:26 PM  

$smarty->template_dir = 'C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = 'C:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';
$smarty->assign('name','Penguin !!');
$smarty->display('index.tpl');

Anonymous said... / August 11, 2010 8:19 PM  

Can you Help me.. It's not working for me. and I don't how to do it, it's my first time to try the smarty configuration.

this is the (C:\xampp\php\php.ini),

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
include_path = ".;C:\xampp\php\pear\;C:\xampp\smarty\libs\"


Parse error: parse error in C:\xampp\htdocs\index.php on line 5

This the error.

i'll try to execute this ==== , b ut it the same error.

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path ==== ".;c:\php\includes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
include_path = ".;C:\xampp\php\pear\;C:\xampp\smarty\libs\"

Can you help me. what is wrong of this execution?


By the way I'm Darryl, I want to learn smarty combination of php.


Please help me.

Anonymous said... / September 01, 2010 2:38 PM  

I have gone through the steps provided here to install smarty.
After installation I restarted my apache server too.
Now I am getting an error like:
Warning: Smarty error: unable to read resource: "index.tpl" in C:\xampplite\smarty\libs\Smarty.class.php on line 1093
Can you please help me?

M.b.b.a said... / October 08, 2010 1:59 PM  

Warning: require(Smarty.class.php) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\smarty\index.php on line 3

Fatal error: require() [function.require]: Failed opening required 'Smarty.class.php' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\smarty\index.php on line 3
I am getting above error
i change the include_path but it still not loading smarty library...
plz help me in this...

Anonymous said... / October 31, 2010 9:03 PM  

Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\Smarty\index.php on line 5

Anonymous said... / October 31, 2010 9:10 PM  

$smarty-»template_dir = 'C:/xampp/htdocs/smarty/templates';

The -> double >> sign is creating error kindly remove it.

Anonymous said... / February 24, 2011 3:52 AM  

Thanks.Work perfectly for me after replacing >> with ->

Anonymous said... / March 11, 2011 2:38 PM  

I am getting this error :


Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'index.tpl'' in C:\xampp\Smarty\libs\sysplugins\smarty_internal_template.php:163 Stack trace: #0 C:\xampp\Smarty\libs\sysplugins\smarty_internal_template.php(550): Smarty_Internal_Template->isExisting(true) #1 C:\xampp\Smarty\libs\Smarty.class.php(338): Smarty_Internal_Template->getRenderedTemplate() #2 C:\xampp\Smarty\libs\Smarty.class.php(382): Smarty->fetch('index.tpl', NULL, NULL, NULL, true) #3 C:\xampp\htdocs\smarty\index.php(16): Smarty->display('index.tpl') #4 {main} thrown in C:\xampp\Smarty\libs\sysplugins\smarty_internal_template.php on line 163

pls help

Md Shakil Hossain said... / April 26, 2011 6:28 PM  

Thanks for your great post. I found it helpfull to install smarty in my pc

Andreea said... / July 21, 2011 8:20 PM  

Thank you! This hepled me a lot!

Anonymous said... / September 06, 2011 3:20 PM  

my solution are :

template_dir = 'C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = 'C:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';
$smarty->assign('name','Penguin !!');
$smarty->display('index.tpl');
?>

Anonymous said... / September 06, 2011 3:21 PM  

template_dir = 'C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = 'C:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';
$smarty->assign('name','Penguin !!');
$smarty->display('index.tpl');
?>

Anonymous said... / September 06, 2011 3:24 PM  

this textbox eat my codes head
why?
<?php
$SMARTY_DIR='C:/xampp/smarty/libs/';
require($SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty;

sarita said... / September 15, 2011 3:44 PM  

thanks in my system smarty running well...

ratnesh said... / December 09, 2011 12:59 PM  

Hi,

i have upload all smarty file in in server by FTP .Then show that error
Fatal error: require_once() [function.require]: Failed opening required '../main.php' (include_path='.;./includes;./pear') in C:\Inetpub\vhosts\kormanmd.perfectyourself.net\httpdocs\index.php on line 6

Help please

Anonymous said... / January 12, 2012 1:38 PM  

Its good for beginner. really I got too must help

Anonymous said... / January 19, 2012 11:16 PM  

It works!!! after you change the sign, explainned above, you may say to program how to find the 'Smarty.class.php'. Following the right directorie it shoud be:
require('C:xampp/smarty/libs/Smarty.class.php');

Anonymous said... / February 08, 2012 6:19 PM  

not working

fakhruddin said... / April 30, 2012 5:07 PM  

Very nice example of doing/installing with xampp

Thanks

Unknown said... / July 23, 2012 3:03 AM  

yeah it's working.... thank sir

Unknown said... / July 23, 2012 3:06 AM  

Add below line in index.php at 3rd line....

require($SMARTY_DIR.'Smarty.class.php');

Unknown said... / July 23, 2012 3:07 AM  

replace ->> with ->

Renown web said... / September 08, 2012 8:59 PM  

nice post on smarty config..
good work...
it will definitely help beginners...

amyth said... / November 12, 2012 6:40 PM  

Nice One!!! I Configured successfully.
Thank you!!!!! :-D

Unknown said... / December 19, 2012 2:35 PM  

Hi..
I like your product & it's information....

Give us some more details about your product...

Thank you....

Weighing Scale | Digital Scale

Unknown said... / February 13, 2013 1:41 AM  

Notice: Undefined variable: SMARTY_DIR in C:\xampp\htdocs\smarty\index.php on line 3

Warning: require(Smarty.class.php): failed to open stream: No such file or directory in C:\xampp\htdocs\smarty\index.php on line 3

Fatal error: require(): Failed opening required 'Smarty.class.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\smarty\index.php on line 3


goveing theses errors please help!!!!!!!!!!!!!!!

Anonymous said... / May 10, 2013 6:57 PM  

Such helping tutorial!! Thanx a lot!!

Anonymous said... / August 28, 2013 4:11 PM  

got it correct.. thank u.. :)

Unknown said... / October 04, 2013 12:26 PM  

I done it.....Good tutorial to configure smarty.....great...

Anonymous said... / December 01, 2013 9:32 PM  


Warning: require(Smarty.class.php): failed to open stream: No such file or directory in C:\xampp\htdocs\smarty\index.php on line 3

Fatal error: require(): Failed opening required 'Smarty.class.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\smarty\index.php on line 3

Unknown said... / October 01, 2015 1:37 AM  

Thank You! You are the BEST!

Unknown said... / October 22, 2015 11:55 AM  

it's work. Thank you so much.

Unknown said... / November 18, 2015 2:32 AM  

Warning: require(Smarty.class.php): failed to open stream: No such file or directory in C:\xampp\htdocs\smarty\index.php on line 4

Fatal error: require(): Failed opening required 'Smarty.class.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\smarty\index.php on line 4

Anybody help me on the above error. i m beginner on Smarty ....

Anonymous said... / December 28, 2015 7:07 PM  

Very nice post, impressive. its quite different from other posts. Thanks for sharing.

buy weighing scale online

tejas said... / December 13, 2016 4:15 PM  

Easy Steps To config Thanks.

Anonymous said... / December 22, 2016 11:09 PM  

guys just put that line in ".;C:\xampp\php\pear\;C:\xampp\smarty\libs\" on the path and directories. i had the same problem just change it it will work on windows. i have solved it..

Anonymous said... / April 10, 2017 12:32 AM  

Warning: require(Smarty.class.php): failed to open stream: No such file or directory in C:\xampp\htdocs\smarty\index.php on line 3

Fatal error: require(): Failed opening required 'Smarty.class.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\smarty\index.php on line 3

Eurimar said... / April 24, 2017 1:41 AM  

Hi, i got this problem and i don't know what to do. My php file do not show my tpl, instead it show the php file as text file.

Weighbridge Manufacturer in India said... / January 29, 2018 7:51 PM  

thanks for sharing informative information about weighbridge for my business. it is very important article Tank Weighing System for me.

Unknown said... / June 06, 2019 3:25 PM  

Can you help me I;m getting this error :
Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\smarty\index.php on line 5

Unknown said... / August 20, 2019 12:20 PM  

hai can u send me class.php file

sharif said... / August 29, 2019 5:39 PM  

dynamometers
load cell

https://www.ron-crane-scales.com/

Eilon Engineering specializes in the manufacture of crane scales, dynamometers, and load cell. We manufacturing high-quality digital crane scales, dynamometers, and load cell with the last 40 Year experience.

alfieindesigns said... / June 23, 2020 10:48 AM  
This comment has been removed by the author.
alfieindesigns said... / June 23, 2020 10:50 AM  
This comment has been removed by the author.
alfieindesigns said... / June 23, 2020 10:52 AM  

Here's a working example: Just make sure you point the right path for 'Smarty.class.php'

<?php
// load Smarty library
require('C:\xampp\smarty\libs\Smarty.class.php');
$smarty = new Smarty;
$smarty->config_dir = 'C:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';
$smarty->assign('name','Penguin !!');
$smarty->display('index.tpl');
?>

Post a Comment