Smarty Template Step By Step Tutorial - Part 3: After create folder needed to operate Smarty template at previous post, in this post, we try to test it. We want to create a page to show simple hello text. Let's do it.
First, we do with template file. Create a file named "test.tpl" within template folder. Enter following code:
<html>
<head>
<title>{$title}</title>
</head>
<body>
{$hello}
</body>
</html>
Next, create a php file named "test.php" within www/test/smarty. Enter following code:
<?php
require 'Smarty/libs/Smarty.class.php';
$smarty = new Smarty;
$smarty->assign('title','Hello World');
$smarty->assign('hello','Hello World, this is my first Smarty!');
$smarty->display('test.tpl');
?>
This is our structure:

Now, test it by pointing your browser to http://localhost/test/smarty/test.php. You may get like this:
advertisements
blog comments powered by Disqus

