ASP, PHP and JSP: The beauty of dynamic content, statically.
October 23rd, 2005I recently migrated a simple but templatic site to ASP to encapsulate the page structure so that changes to it could be done in one place. Tonight I migrated the same site to PHP. The beauty of this dynamic content doesn’t just lie within the ability to retrieve from a database, it lies within included functions where visual logic can be encapsulated and reused.
For instance, I created functions fHTMLHeader(), fLeftBody() and fHTMLFooter(). Within these functions is the html to write the header, left navbar and footer. So instead of coding these things in every page, I just create pages like this:
<?php
include_once('functions.php')
?>
<?php
fHTMLHeader()
?>
<?php
fBodyLeft()
?>
<!-- add content here -->
<?php
fHTMLFooter()
?>I’m new to dynamic web design, but I just think it’s great how easy it is to reuse code and templates without any fancy-ness.

To take this one step further, the “add comments here” section could be another function call based that returns the content based on a POST or GET request. This way all of the content would be returned from one place. In essence there would be three likely files: index.php, template.php and content.php
index.php would get params from POST or GET requests and pass them to a function, say fContent(), which is included from content.php. This function uses a case statement to write out the dynamic content based on the passed parameter.
This way, anytime you’d like to add content to your site, you add it in one place and let the format you have already in place handle it.
I’m all about automation and not having to code things more than once…