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  
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 
Moblin 
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 - 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 fileinclude("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 sinceyour 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

    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP





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