I'm using a PHP based front controller pattern such that index.php
provides the page structure and template, and all content for each page is in include files within /pages/
.
index.php
/pages/home.inc
/pages/about.inc
/pages/contact.inc
The include pages are mostly simple HTML so that clients can edit the pages without having to get into anything too complex.
The problem with this layout is that because all page information is in the page include, the <title>
element can't get populated. I could put a $title
variable in each include, but it loads after the head, which is too late:
<html>
<head>
<title><?php echo $title; ?></title> #$title is not set yet!
</head>
<body>
<?php include($content); ?> #now $title is set
</body>
</html>
It's important that the content files are self contained and mostly HTML, but with the ability to have PHP code as well, as I mentioned, because customers will be modifying these and adding too much complexity is a problem. Thus, for example, setting up a separate database of page titles won't work because customers won't update the database when they make new pages.
Edit: a typical page include might look like this.
<h1>Welcome</h1>
<p>blah</p>
<?php include("nav.php"); ?>
<p>more blah</p>
<p>more blah</p>
<p>more blah</p>
<?php
$pageJavascript = "alert('js!');";
$pageTitle = "Cyberdyne Welcome Page";
?>
Welcome
` – brentonstrine Feb 10 '15 at 19:23