Smarty Variable: Array Index


Smarty Variable Step by Step Tutorial - Part 2: Following sample using array indexed 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(1,'Wiwit','wsiswoutomo at yahoo dot com','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[0]} <br>
    name : {$contact[1]} <br>    
    email : {$contact[2]} <br>    
    phone : {$contact[3]} <br>    
  </body>
</html>



Bookmark and Share Tag: smarty, template, array, array index, variable Category: PHP Classes Post : May 02nd 2008 Read: 46,658

advertisements


blog comments powered by Disqus