Search This Blog

5/16/2011

Layout

Although I like and encourage the use of PHP, I do not like one of its most significant feature: the fact that the language is HTML embedded. It is the language has code delimiter and all code behind the delimiter is considered text blocks, which are sent directly to the standard output (often it is an HTML code).

This feature is useful to create a layout essencialy in HTML, but with little points of PHP code. This is useful to separate one team focused on HTML + CSS and another team focused on PHP (application handler). Although, in practice, it is often what did not occurs (at least in Brazil). Beginners use this feature to create large blocks of PHP code embeded in large blocks of HTML code. It brings the code very confused and hard to maintain. For this reason, I think it would be better if this feature just would not exist.

Yes, there are alternative ways to that. For example, creating an HTML and making PHP read this HTML, insert dinamically generated HTML code in strategic points, and then, returning a final HTML. For example, using DOM.

Although, I do not often use this feature nor its alternative. I often create methods that returns HTML code. For example, to create a list, a table, etc. This way, it is easy to create this elements, and to maintain the HTML generation. For example, who wants to upgrade from HTML 4.01 to HTML 5 should update only these methods.

An other way, a little advanced, is to use XSLT. This language (that is XML based) serves to transform an XML into an other. This way, it is possible that an application generates an XML that is converted to XHTML using XSLT. The language offers other features like sort list, format text, etc.

No comments:

Post a Comment