Qcodo templates - Adding to the layout
The first installment of this series described a technique for creating a flexible page templating system for Qcodo. This article picks up where that one left off and expands our template to create a more interesting layout for our pages. If you haven’t yet read the first article, you read it here.
For those who prefer to just jump into the middle of the discussion, here is a quick overview of the technique used. An abstract subclass of QForm (ABCForm) was created to take care of the parts of the form that are the same on all pages. Application forms will be subclasses of ABCForm. The form templates were split apart so they contain the code which renders only their specific parts. They no longer contain the or tags, or the RenderBegin() or RenderEnd() calls. The page rendering has been moved to a new template called layoutTemplate.php.inc. This template handles all of the common aspects of the page and requires the form specific template.
So what have we gained?
Looking at layoutTemplate.php.inc we see that while we have accomplished all of our goals, we really aren’t exploiting any of the flexibility gained yet. The only tangible benefit at this point is that each page has it’s own unique HTML title. That’s really nice, but it seems like an awful lot of work just to fix the title.
Create a real layout
The first task is to decide on the layout. Since three column layouts are fairly common, we’ll start there. There is a very good public domain css for three column layout at Real World Style. Thanks to Mark Newhouse for putting the layout in the public domain. Since this is not an article about css layout, I will point you to Real World Style for interesting articles about css techniques.
Now that we have a css file, we need to link it in the layout file. Add this line to the element.
FormTemplate);?>
RenderEnd(); ?>
Now the layout is starting get more useful. We’ll start by adding something interesting to the header. There are a couple of options here. We can simply put the heeader information into the header div in layoutTemplate.php.inc, or we can add more flexibility by storing the header info in a seperate file and requiring it in the header div. Better still, we will add a property to ABCForm which contains the name of the header file. In this way, we can set the property in ABCForm to the default header used by most pages, while still retaining the flexibility to change the header file for each form page that needs to.
Here is what gets added to ABCForm.php
protected $headerTemplate = 'header.php.inc';
Here is what changes in layoutTemplate.php.inc
HeaderTemplate);?>
Finally, I created an extremely simple header which only contains a single image. Here is the etire source for header.php.inc FooterTemplate);?>