Home arrow PHP arrow Page 4 - PHPLib Templates

Let's get started - PHP

PHPLIB templates can grant you an amazing ability to abstract the manipulation of data (in the database as well as in PHP) from its final format, whether that format is HTML, XML, WML, or a formatted e-mail, and some of these ways will be explored here.

TABLE OF CONTENTS:
  1. PHPLib Templates
  2. Simplify
  3. Home is where the heart is
  4. Let's get started
  5. Dealing with blocks
  6. Nested blocks...
  7. Aren't we done YET?
  8. Closing
By: Benjamin D. Smith
Rating: starstarstarstarstar / 21
February 28, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Let's say you have a file, we'll call it 'one.ihtml', (The name, as well as the extension is completely arbitrary) and the template class is already instantiated inside object variable $T:

one.ihtml:

My name is {username} and I want to tell you {message}.

First off, we need to define a variable for the entire file..

<? $T->set_file('input_one', 'one.ihtml'); ?>

And there's two variables in this file, 'username' and 'message'. We'll need to define these:

<? $T->set_var('username', 'Henry'); $T->set_var('message', 'a message'); ?>

Now that we've set the variables in memory, we want to take the file variable and create some output:

<? $T->parse('Output', 'input_one'); ?>

Now, we have a total of four variables:

1) 'input_one' contains the original file we loaded. It contains two other variables within it.

2) 'username' contains the text string 'Henry'.

3) 'message' contains the string 'a message'.

4) 'Output' contains the original file with the variables replaced with the values we assigned... 'My name is Henry and I want to tell you a message.'

Likely as not you want to print the 'Output' variable to the screen. To do this, use pparse instead of parse:

<? $T->pparse('Output', 'input_one'); ?>

or just print the feecback of the parse function:

<? echo $Tparse('Output', 'input_one'); ?>

Simple so far? Read on...



 
 
>>> More PHP Articles          >>> More By Benjamin D. Smith
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: