Smarty Variable Step by Step Tutorial - Part 4: We can store variables at configuration file. For this job, we must create a folder named configs within root application (example, www/test/smarty). So, we have www/test/smarty/configs.
Create a configuration file with conf extension, such as "setting.conf". Enter following sample code:
pageTitle = "Hello, World" bodyColor = "#EAEAEA"
Next, build template by create a file named "test.tpl" within template. Enter following code
{config_load file="setting.conf"}
<html>
<head>
<title>{#pageTitle#}</title>
</head>
<body bgcolor="{#bodyColor#}">
id : {$contact->id} <br>
name : {$contact->name} <br>
email : {$contact->email} <br>
phone : {$contact->phone} <br>
</body>
</html>
Create a file named "test.php" enter following code:
<?php
require 'Smarty/libs/Smarty.class.php';
class Contacts{
var $id = 1;
var $name = 'wiwit';
var $email = 'wsiswoutomo at yahoo dot com';
var $phone = '123456789';
}
$contact = new Contacts;
$smarty = new Smarty;
$smarty->assign('contact',$contact);
$smarty->display('test.tpl');
?>
advertisements
blog comments powered by Disqus

