Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Templates: Home Brew or Plug-n-Play

Status
Not open for further replies.
Aug 27, 2001
502
US
In the past, I would just echo my HTML within my PHP code. I am a bit wiser now and have learned that this is very inefficient for a number of reasons. Lately I've been exploring different ways of separating my HTML from my PHP code. I tried Smarty ( but didn't care much for it. So, I'm now searching for suggestions on how others separate their HTML & PHP.

I know it's usually a matter of personal preference & style, but I was wondering if you'd be willing to share how you perform the separation. Do you use a "out of the box" template system? Or, do you have a system of include files? Or, perhaps you code everything in "Object Oriented" fashion? What are the advantages & disadvantages to these different approaches? Which is most efficient from a coding standpoint (using a separate designer & developer) & which is most efficient from a server process point of view?

Thanks a bunch!
-Ron

We all play from the same deck of cards, it's how we play the hand we are dealt which makes us who we are. -Me

murof siht edisni kcuts m'I - PLEH
 
I have been working with a modified template class that allows me to separate code and design completely.

The issues involved with templates are:
1. Performance: do you need a template system that compiles because otherwise system performance would suffer? The system I use is not compiled, just pure HTML read into a variable and parsed. I have the luxury o a server farm with 3 powerful quad-processor Solaris based servers.

2. Maintainability: I prefer a template system that allows editing the HTML portion in a web design tool such as Macromedia's Dreamweaver. Smarty for example - and other template classes/systems - use chunks of HTML. One of the hardest and most frustrating tasks is to debug HTML produced by a script from nested chunks. A single template file edited in a powerful HTML editor that validates the code is highly preferable and enhances productivity.

3. Portability: A siple template class allows another layer of abstraction for projects. Multi-customers can put whatever look on it without having to touch the code. The use of CVS just for the code portion is extremely helpful as just code changes are tracked. Design can be tracked in a separate branch of CVS.

Here's an example for a template based application:
- with a general template

Customers can edit their templates as they wish. The code is never disturbed.

The template class we use creates a template object. Methods are applied to it. It's important to be able to have a template class produce different kind of output:

1. The parsed template to the browser
2. The parsed template to a variable
3. Extracted <body>...</body> content to a variable

This allows to have nested templates where the sub-templates are still valid HTML files that can be edited in DW for example.


Hope these few hints and opinions help.
 
I've done some work using XSLT to render my pages. I generate an XML file and style it with an XSLT stylesheet. I went down this route as I was asked about replacing the presentation layer in a project. The XML can now be used in web apps (any type). fat client, batch job etc etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top