PHP
  Home arrow PHP arrow Page 5 - 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  
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

Web Development With PHP FastTemplate
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    Web Development With PHP FastTemplate - Repeat Customers
    ( Page 5 of 9 )

    Another nifty little feature you'll find in FastTemplate is the ability to "nest" one template within another - in the following example, a welcome message template is nested within the main index page template.

    <!-- begin: message.tpl --> <div align=center style="font-family: Verdana; font-size: 10pt"> {MESSAGE} </div> <p> <!-- end: message.tpl --> <!-- begin: welcome.tpl --> <html> <head> </head> <body> {CONTENT} <hr> </body> </html> <!-- end: welcome.tpl -->
    Here's the script which puts them together:

    <? // index.php - welcome page // include class file include("class.FastTemplate.php3"); // instantiate new object $obj = new FastTemplate("./tmpl/"); // assign names for template files $obj->define(array( "welcome" => "welcome.tpl", "message" => "message.tpl" )); // normally, this variable might be set from a cookie // uncomment this to see how the message changes // $repeat_visitor = 1; // assign values to FT variable within the template if ($repeat_visitor == 1) { $obj->assign("MESSAGE", "Welcome back! We've updated our catalog since your last visit - click here to see the new arrivals."); } else { $obj->assign("MESSAGE", "You're visiting our site for the very first time, so you might like to take our New User Tour."); } // parse templates // in this case, "message" is parsed first // the resulting output is assigned to the FT variable CONTENT // the next template "welcome" is parsed $obj->parse(CONTENT, array("message", "welcome")); // and print $obj->FastPrint(CONTENT); ?>
    When the parse() method is assigned a series of templates to parse via an array, FastTemplate will proceed through the array in a sequential manner, assigning the result of each successive parse() operation to the variable specified.

    In this case, FastTemplate will first parse the template "message", assign a value to the "MESSAGE" variable, and then assign the result to the variable "CONTENT". At this stage, the variable "CONTENT" contains:

    <!-- begin: message.tpl --> <div align=center style="font-family: Verdana; font-size: 10pt"> You're visiting our site for the very first time, so you might like to take our New User Tour. </div> <p> <!-- end: message.tpl -->
    Next, it will proceed to parse "welcome", assign the value of the newly-created variable "CONTENT" to the template, and again store the result in "CONTENT". At this stage, the variable "CONTENT" contains:

    <!-- begin: welcome.tpl --> <html> <head> </head> <body> <!-- begin: message.tpl --> <div align=center style="font-family: Verdana; font-size: 10pt"> You're visiting our site for the very first time, so you might like to take our New User Tour. </div> <p> <!-- end: message.tpl --> <hr> </body> </html> <!-- end: welcome.tpl -->
    This is what finally gets printed to the browser via FastPrint().

    Note also that you can assign values to FastTemplate variables on the basis of conditional tests; in the example above, the message changes depending on whether or not the user is a repeat visitor.

     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    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 4 hosted by Hostway
    Stay green...Green IT