PHP
  Home arrow PHP arrow Page 2 - Simple PHP Templates With PatTemplate
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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

Simple PHP Templates With PatTemplate
By: Havard Lindset
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 191
    2002-06-26

    Table of Contents:
  • Simple PHP Templates With PatTemplate
  • An Overview Of PatTemplate
  • How to Process Template In PHP
  • Different Template Types
  • Template Visibility
  • Conclusion

  • 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


    Simple PHP Templates With PatTemplate - An Overview Of PatTemplate


    (Page 2 of 6 )

    The first thing I noticed about patTemplate was it's ease of use. When you make your templates, you divide your document into different parts by using XML-tags. Here is an example of a template:

    <patTemplate:tmpl name="article">
    <html>
    <head>
    <title>A patTemplate example</title>
    </head>
    <body>
    <h3>{HEADLINE}</h3>
    {CONTENT}
    </body>
    </html>
    </patTemplate:tmpl>


    When patTemplate parses this file, it looks for variables and replaces them with their associated values. In this case {HEADLINE} and {CONTENT} are the variables. We will see how we can assign values to these placeholder variable on the next page. Right now we will see how easy designing a template can be.

    Here's some of the key-features of patTemplate (taken directly from the patTemplate site):
    • Use special XML tags to separate a document into templates
    • Use an infinite amount of templates in one page
    • Read from several plain html files
    • Local and/or global variables
    • Automatic repetition of templates to build lists
    • Automatically create alternating lists by using OddEven templates
    • Automatically enumerate entries in list
    • Templates can have child templates
    • Subtemplates to do simple if(); elseif(); else(); statements
    • Strip or replace unused variables from HTML
    • Hide/Show templates in a document
    • Read external files with/without parsing them
    • Strip leading/trailing whitespace in lines for smaller HTML code
    • Use a template several times in a document by linking to it
    • Quote template tags to use them in a second parsing process (enables you to build templates from templates)
    • Output any ASCII format you like (HTML, txt, XML, LaTex, etc)
    A basic example
    Let's take another look at the example we saw earlier. It's pretty basic, but I'll explain every part of it:

    <patTemplate:tmpl name="article">
    <html>
    <head>
    <title>A patTemplate example</title>
    </head>
    <body>
    <h3>{HEADLINE}</h3>
    {CONTENT}
    </body>
    </html>
    </patTemplate:tmpl>


    Let me explain the different parts of this example.

    <patTemplate:tmpl name="table">

    This is a special patTemplate tag that defines a template. The attribute "name" sets the name of the template, which by the way has to be unique as the patTemplate makes calls to different templates using their unique names.

    {HEADLINE}

    This is a variable. Variables works as placeholders for the actual content. I should probably mention that variables can only contain uppercase characters, numbers and the underscore (_). They are always enclosed in curly braces.

    </patTemplate:tmpl>

    This is yet another patTemplate tag which marks the end of a template. If you're used to XML then should be pretty self-explanatory.

    In the next section we'll see how we can replace the placeholders with actual content. Before we continue, save the example above as "example1.tmpl.html".

    More PHP Articles
    More By Havard Lindset


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek