Good ways of planning HTML

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Good ways of planning HTML

Post by jolinar »

Lately, I abandoned work on a gallery since the HTML was hard coded in to most of the program. This had the problem of making a mess which was difficult to follow, and HTML which was frequently out of alignment. Recently I have started work on a new gallery with a new HTML writer ans I was wondering if anyone could say whether the following setup is a good idea:

writer.php (class writer), this deals with the nitty-gritty of putting text and tags onscreen. It has a constructer to set an indent counter, basic output functions for raw text (no tags), opening tags, closing tags and one for empty type tags (<br/> etc)

HTMLinterpreter.php (class HTMLinterpreter), this creates an instance of writer and in its constructor. Its methods deal with text output, and ones for opening and closing all types of tags.

builder.php (class builder), creates an HTMLinterpreter in its constructor and has functions such as createTitle($text,$level) which makes calls to several functions on HTMLinterpreter.

The idea I had with it is to make the classes become pregressivly more high level until it reaches builder, which does not have the user say what HTML they want, but what they want doing.

Any thoughts?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

If you're after seperation why not use an exsisting templating system like Smarty?

I built a gallery system where the html was intermixed. Wasn't that bad, only a couple three methods have html intermixed. Click on the link in my signature to see the script. I'm not entirely sure what "pattern" it meets. But I think it is a "front controller" set up.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Personally, I don't like classes which write out html. IMO code should stick to gathering & manipulating data, then make this available to a template where all the formatting is applied.

This makes the code simpler and easier to test. Also, with formatting applied by php, designers working with Dreamweaver etc have a hard time. They may not know any php. They may not have a local server installed - or know how to install one. They certainly don't want to have to upload each edit to a live site in order to pass it by a server. Design involves lots of fiddly little changes and they all need to be previewed. It might take over a dozen steps to find just the right shade of mauve which works with that tree-frog green header. Or not.

They just want to work the way the normally do ie with whole pages from DOCTYPE all the way to </html> (no template fragments) which they can preview in a browser without having to pass it through a server.

A template "compile" stage can be used to avoid exposing designers to even the simplest php code (it doesn't look simple to them). The designer's template could have a bunch of xml-like tags which they're more or less used to. When they're done designing, these can be replaced by php echo's, loops and conditionals to create a run-time template.
Post Reply