Home arrow PHP arrow Building a Site Engine with PHP, Part 4

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

  1. Building a Site Engine with PHP, Part 4
  2. You’ve been Tagged
  3. Give it a Little Class:
  4. The Final Words
By: James Murray
Rating: starstarstarstarstar / 24
July 12, 2004

print this article



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:


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

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

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

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

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

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

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


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



















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.





<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>


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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: