Skip to navigation

malevolent design weblog

This blog is now defunct, but you can find more stuff over at my personal site

Similar Templating

Dave Shea’s approach to building up pages is a lot like my “Tesco Value” templating system used for small sites, although I tend to opt for functions rather than multiple includes to improve security and performance (several commenters made similar suggestions).

For example, a simple page might use a bit of PHP:

<?
require_once($_SERVER['DOCUMENT_ROOT'].'/somewhere/something.php');

$section = 'services';   //site section the page is in
$title = 'Example Page'; //main bit of page title
$style = 'subpage';      //class to add to body tag

//metadata
$description = 'An amazing example page.';
$keywords = 'template,php,hacky';

pageStart();
?>

<p>Page content</p>

<?
pageEnd();
?>

The functions use the global variables to build up the layout, highlight the current section in the navigation, etc., with a few simple if statements. For larger sites you need to look at things like XSLT and Smarty, but don’t feel compelled to overcomplicate.


Comments


Comments are now closed for this entry.