Mobile-Menu iFuturz Infoweb Inc. Contact Portfolio

07

Sep

How to assign Smarty Variable using Object

How to assign Smarty Variable using Object

Posted On : September 7, 2013

| No Comment

In Smarty Framework widely used today as template based engine. So developer can easily update site layout without touch php code. Lets see how to assign smarty variable using object

#Create file name of contact.php. Enter following code

require 'Smarty/libs/Smarty.class.php';
 
class contactinfo{
var $id = 1;
var $name = 'demo';
var $email = 'demo@gmail.com';
var $phone = '9859596859';
}
 
$contact_detail = new contactinfo; 
 
$smarty = new Smarty;
 
$smarty->assign('contact_detail',$contact_detail);
$smarty->display('contact.tpl');

#create a file named “contact.tpl” within template. Enter following code

View Code SMARTY
	 id : {$contact_detail ->id} <br>
 
    name : {$contact_detail ->name} <br>    
 
    email : {$contact_detail ->email} <br>    
 
    phone : {$contact_detail ->phone} <br>  

 

  • Tags:

Comment