What is Smarty
Smarty is Template Engine which separate presentation framework and program logic.
"Is Smarty right for me" from smarty.com
Setup Smarty and testing
Below step done in Windows XP and using Apache Web Server.
1. Download Smarty
2. Unzip Smarty-2.6.14.tar with using commercial software winzip or freeware 7-ZIP
3. Extract and copy Smarty directory outside of root directory. Example c:\smarty
4. Locate php.ini path location with phpinfo.php
5. Include this in php.ini
include_path = ".;c:\smarty\libs"
6. Restart IIS/Apache
7. Setup 2 folder in root directory
smarty/templates
smarty/configs
8. Testing
A. Create smartytest.php
template_dir = 'c:/program files/Apache Group/Apache2/htdocs/smarty/templates';
$smarty->config_dir = 'c:/program files/Apache Group/Apache2/htdocs/smarty/config';
$smarty->cache_dir = 'c:/smarty/smarty_cache';
$smarty->compile_dir = 'c:/smarty/smarty_templates_c';
$smarty->assign('name','world!');
$smarty->display('index.tpl');
?>
B. create template smartytest.tpl
put into \smarty\template
put the below code into page which contain html and body and save as smartytest.tpl
Hello, {$name}!
C. Create folder
c:\smarty\smarty_cache
c:\smarty\smarty_templates_c
D. testing
http://localhost/smartytest.php
E. Result
Hello, World!!
No comments:
Post a Comment