Is there any way to combine transparency and "ajax usability" with HTML templates
- by Sam
I'm using HTML_Template_Flexy in PHP but the question should apply to any language or template library. I am outputting a list of relatively complex objects.
In the beginning I just iterated over a list of the objects and called a toHtml method on them. When I was about to have my layout designer look over the template I noticed that it was too opaque and that he would have ended up looking through and/or editing many additional php source files to see what really gets generated by the toHtml method.
So I extracted most of the HTML strings in the php classes up to the template which made for one clear file where you can see the whole page structure at once. However this causes problems when you want to add an object to the list using javascript. Then I have to keep the old toHtml method and maintain both the main template and the html strings at the same time, so I can output just the HTML for a new object that should be added to the page.
So I'm back to the idea of using smaller templates for the objects that make up the page, but I was wondering if there was some easy way of having my cake and eating it too by having one template that shows the whole page but also the mini-templates for smaller objects on the page.
Edit:
Yes, updating the page is not a problem at all. My concern is with having both maintainability and transparency of the template files.
If I have one single template for the whole page, then I must maintain mini-templates of the objects that are shown on the page.
If I just have the mini-templates and include them from the higher-level template it becomes more difficult to look at the top-level html and imagine what the end result will look like.