phpeveryday.com

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


Smarty Variable: Variable at Configuration File

Tag: smarty, template, variable, config   Category: PHP Classes
post: 03 May 2008 read: 242


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');
?>



| 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