Smarty is a web template system written in PHP.
Although Smarty is known as a "Template Engine", it would be more accurately described as a "Template/Presentation Framework." That is, it provides the programmer and template designer with a wealth of tools to automate tasks commonly dealt with at the presentation layer of an application. I stress the word Framework because Smarty is not a simple tag-replacing template engine. Although it can be used for such a simple purpose, its focus is on quick and painless development and deployment of your application, while maintaining high-performance, scalability, security and future growth.
I'm using Smarty many months ago, But I didn't build an application from scratch so far and I felt that I need to implement the Hello world demo to satisfy my ambition.
Smarty really was very easy installed and used, and here is my demo.
Code Snippet:
index.php
<?php
// put full path to Smarty.class.php
require('smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'templates';
$smarty->compile_dir = 'smarty/templates_c';
$smarty->cache_dir = 'smarty/cache';
$smarty->config_dir = 'smarty/configs';
$smarty->assign('name', 'World');
$smarty->display('index.tpl.html');
?>
index.tpl.html
<html>
<head>
<title>Smarty</title>
</head>
<body>
Hello, {$name}!
</body>
</html>
Download Code 100 KB
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment