PHP
  Home arrow PHP arrow Building a Site Engine with PHP, Part 4
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

Building a Site Engine with PHP, Part 4
By: James Murray
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 24
    2004-07-12


    Table of Contents:
  • Building a Site Engine with PHP, Part 4
  • You’ve been Tagged
  • Give it a Little Class:
  • The Final Words

  • 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


    Building a Site Engine with PHP, Part 4
    ( Page 1 of 4 )

    In the last three articles we went over a basic idea of how a site engine works, how to build the plug-in, module, and block systems, the basic directory structure, the database structure, and the authentication methods. In this, the fourth article, we’ll be going over the template system, and the basic page loading methods. So, let’s go ahead and get started.

    XML and HTML and CSS, Oh My!

    XML is a really cool language to use for a template system. Coupled with PHP5, you almost have a hybrid of languages that I like to refer to as Object-Oriented HTML. It makes you want to say “OOH!” and "Ahh!".

    The templates are made up of an XML document that contains each piece of our layout as a separate XML element in HTML form. At that point most people say “What!?” Well, for each element, we embed the HTML as CDATA. What we end up with is a Header element that contains the HTML from the <html> to the spot that your first content column starts. Then there is the Body element that contains the area that will hold all our content columns. Following that we have the Footer, which contains our content to the </html>. Then we have our three column elements which hold the HTML for each of our content columns, then the Block element, which contains the HTML for the layout of our blocks.

    Basically this is what the XML document will look like:

    <template>

    <header> <![CDATA[]]></header>

    <body> <![CDATA[]]></body>

    <footer> <![CDATA[]]></footer>

    <column1> <![CDATA[]]></column1>

    <column2> <![CDATA[]]></column2>

    <column3> <![CDATA[]]></column3>

    <block> <![CDATA[]]></block>

    </template>

    Not too hard to follow. If we were to break it down into the order it is loaded, it would look like this:

    <header>

    </header>

    <body>

    <column1>

    <block>

    </block>

    </column1>

    <column2>

    <block>

    </block>

    </column2>

    <column3>

    <block>

    </block>

    </column3>

    </body>

    <footer>

    </footer>

    The example above shows only one block in each column, but chances are most pages will contain more than one block per column. Here is a rather crude example of what a finished template file would look like.

    <template>

    <header><![CDATA[<html>

    <title><!title></title>

    <body>

    <div style="width:100%;text-align:center;">header!</div>]]></header>

    <body><![CDATA[<div style="width:100%"><!content></div>]]></body>

    <footer><![CDATA[<div style="width:100%;text-align:center;">footer!</div></body></html>]]></footer>

    <column1><![CDATA[<div style="width:25%;float:left;text-align:center;"><!column1></div>]]></column1>

    <column2><![CDATA[<div style="width:50%;float:left;text-align:center;"><!column2></div>]]></column2>

    <column3><![CDATA[<div style="width:25%;text-align:center;"><!column3></div>]]></column3>

    <block><![CDATA[<div style="width:100%;text-align:center;"><!block_data></div>]]></block>

    </template>

    A real one would contain much more complex html, but for the sake of an example, that does the job. It will work as a full template. As you can see there are a few proprietary tags in the html, such as <!title>. We talked a little about those in the fourth part of the first article. Now is the time to talk a little more about them.



     
     
    >>> More PHP Articles          >>> More By James Murray
     

       

    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