Trong htdocs của Xampp, tạo thư mục project mới, đặt tên testsmarty. Trong bài viết này thư mục testsmarty này sẽ được hiểu là thư mục gốc.
Bung nén Smarty, copy thư mục lib vào thư mục testsmarty
Trong thư mục testsmarty này, tạo 3 thư mục bắt buộc như sau: cache, themes, templates_c
Trong thư mục themes, tạo thư mục chứa tempalte tên là daipho.
Đây là cấu trúc bắt buộc phải có để chứa mã nguồn (source code), template của chương trình
Tạo file index.php tại thư mục gốc với nội dung khởi tạo như sau:
<?php
require './lib/Smarty.class.php'; //khai báo thư viện smarty
define('themes', './themes/daipho/'); //khai báo giá trị mặc định
$smarty = new Smarty; // instantiates an object $smarty of class Smarty
$smarty->caching =true; //enable the caching
$smarty->assign ('name', 'hello world'); //used to assign values to the templates
$smarty->display (themes. 'HelloWorld.tpl'); //this is used to display the template
?>
Trong thư mục daipho, tạo file HelloWorld.tpl
<html>
<head>
<title>My first Smarty program</title>
</head>
<body>
{*This is a comment line of smarty *}
{$name}{*Smarty will replace the assigned content *}
</body>
</html>

Bây giờ bạn có thể chạy thử chương trình:
http://localhost:81/hello
Chúc các bạn thành công!







