PHP
  Home arrow PHP arrow Page 5 - PHPLib Templates
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHPLib Templates
By: Benjamin D. Smith
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2001-02-28


    Table of Contents:
  • PHPLib Templates
  • Simplify
  • Home is where the heart is
  • Let's get started
  • Dealing with blocks
  • Nested blocks...
  • Aren't we done YET?
  • Closing

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    PHPLib Templates - Dealing with blocks
    ( Page 5 of 8 )

    Now we get to dealing with blocks.

    Really, it's just more of the same...

    We define some variables with some stuff in them, and then we shuffle the variables around to get what we want.

    Let's take a file called 'two.ihtml'...

    A list of what I want for Christmas: <OL> <!-- BEGIN AccessBlock --> <LI> {item} <!-- END AccessBlock --> </OL>

    Now, we have two types of buckets we want to manipulate text in: a variable, and a block.

    First, we define the variable that contains the entire file...

    <? $T->set_file('input_two', 'two.ihtml'); ?>

    and then we want to break out the block...

    <? $T->set_block('input_two', 'AccessBlock', 'ABlock'); ?>

    What did we just do here?

    We now have three PHPLIB template variables defined here:

    1) 'AccessBlock', which contains the text '<LI> {item}'

    2) 'ABlock', which is a place-holder for where AccessBlock USED to be, and is now a variable, dealt with like any other variable!

    3) 'input_two', which contained the original text of file two.ihtml MINUS the block we've just removed, which has been replaced with the variable tag 'ABlock'.

    When 'AccessBlock' was removed from 'input_two', the text of '<LI> {item}' was taken out of the 'input_two' variable and replaced with the 'ABlock' variable.

    Now, let's assume that we have an array of stuff we want for Christmas:

    $want_list=array( 0 => 'Baseball bat', 1 => 'Remote Control car', 2 => 'Wagon' );

    We can make that Christmas list very easily here...

    <? for ($i=0; $i<sizeof($want_list); $i++) { $T->set_var('item', $want_list[$i]); $T->Parse('ABlock', 'AccessBlock', true); } $T->pparse('Output', 'input_two'); ?>

    Pretty slick, eh?

    So long as you keep the template block definitions and variable names the same within the source (.ihtml) file, you can use table rows, ordered/unordered lists, BR tags, whatever suits your fancy.



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

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT