PHP
  Home arrow PHP arrow Page 6 - Web Development With PHP FastTemplate
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Web Development With PHP FastTemplate
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2001-09-05

    Table of Contents:
  • Web Development With PHP FastTemplate
  • Who Am I?
  • Proofing The Pudding
  • You've Got Mail
  • Repeat Customers
  • Flavour Of The Month
  • A Strict() Master
  • Musical Chairs
  • A Rose By Any Other Name...

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Web Development With PHP FastTemplate - Flavour Of The Month


    (Page 6 of 9 )

    Another useful FastTemplate feature involves creating a sequence of items by appending to a single variable; this comes in particularly handy when creating HTML constructs like lists and table rows. Consider the following templates:

    <!-- begin: list.tpl --> <html> <head> </head> <body> <ul> {LISTCONTENT} </ul> </body> </html> <!-- end: list.tpl --> <!-- begin: list_item.tpl --> <li>{ITEM} <!-- end: list_item.tpl -->
    In this case, I plan to build a list (from a database) by repeatedly calling the "list_item.tpl" template; this list will then be assigned to a FastTemplate variable named "LISTCONTENT", and substituted in the main page, "list.tpl". Here's the script:

    <? // list.php - item list // include class file include("class.FastTemplate.php3"); // instantiate new object $obj = new FastTemplate("./tmpl/"); // assign names for template files $obj->define(array( "list" => "list.tpl", "list_item" => "list_item.tpl" )); // get item list /* // open connection to database $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); // query $query = "SELECT item from itemtable"; $result = mysql_db_query($database, $query, $connection); // build $items array $items = array(); while(list($item) = mysql_fetch_row($result)) { $items[$count] = $item; $count++; } */ // assume it looks like this.. $items = array("vanilla", "pineapple", "strawberry", "chocolate chip", "peach", "banana", "grape"); // build LISTCONTENT variable by concatenation of multiple instances of "list_item" template for ($x=0; $x<sizeof($items); $x++) { $obj->assign("ITEM", $items[$x]); // append the result of parsing the template to LISTCONTENT $obj->parse(LISTCONTENT, ".list_item"); } // parse templates $obj->parse(RESULT, "list"); // and print $obj->FastPrint(RESULT); ?>
    Each time the loop iterates through the $items array, a new value is assigned to the "ITEM" variable. FastTemplate then parses the "list_item" template and replaces the placeholder with its actual value. The "." operator is used to append the result of each iteration to the "LISTCONTENT" variable.

    This technique comes in very handy when building repetitive sequences - all you need to do is build a template containing one item of the sequence, and let FastTemplate generate as many copies of it as you need.

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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