Monday, 2 April 2007

Best Practice #1: Keep location and naming comments in your templates

In projects with lots of nested templates I once again experienced that it's easier to get a grip on the overall structure if there are simple HTML comments present documenting where the template files are located and how they are named.

Simply by placing comments like <!-- [tmpl] /path/to/template/directory/template.php|tpl|phtml begin|end -->, or something similar, at the start and end of every template file this reduces maintenance and acquisition time for everybody involved, now and in the future. A simple view at the source of the rendered output quickly unfolds all involved templates and their location. This comes in very handy if your not familiar with the template structure of a project and have to expand the provided template data or solve some layout issues.

To avoid revealing parts of the projects directory structure you can strip these comments before deployment via the StripLineComments filter used in a filterchain of Phing, the PHP build tool, and keep them for internal use in the development trunk.

No comments: