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