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:


Next, create a php file named "test.php" within www/test/smarty. Enter following code:

require 'Smarty/libs/Smarty.class.php';

$smarty = new Smarty;

$smarty->assign('title','Hello World');
$smarty->assign('hello','Hello World, this is my first Smarty!');

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: 105,672


blog comments powered by Disqus