Smarty Variable: Associative Arrays


Smarty Variable Step by Step Tutorial - Part 1: Following sample using associative array at smarty:

Create a file named "test.php" enter following code:

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

$smarty = new Smarty;

$smarty->assign('title','Contact Detail');
$smarty->assign('contact',array('id'=>1,
                                'name'=>'Wiwit',
								'email'=>'wsiswoutomo at yahoo dot com',
								'phone'=>'123456789'
                                ));
$smarty->display('test.tpl');
?>

Next, build template by create a file named "test.tpl" within template. Enter following code

<html>
  <head>
    <title>{$title}</title>
  </head>
  <body>
    id : {$contact.id} <br>
    name : {$contact.name} <br>    
    email : {$contact.email} <br>    
    phone : {$contact.phone} <br>    
  </body>
</html>



Bookmark and Share Tag: smarty, template, array, associative array, variable Category: PHP Classes Post : May 02nd 2008 Read: 53,279

advertisements


blog comments powered by Disqus