Smarty Template: My First Smarty


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:




Bookmark and Share Tag: smarty, template, test Category: PHP Classes Post : May 02nd 2008 Read: 91,617

advertisements


blog comments powered by Disqus