phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Smarty Template: My First Smarty

Tag: smarty, template, test   Category: PHP Classes
post: 02 May 2008 read: 323


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:




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting