With respect,
I am looking for a way to organize my HTML markup within PHP for use in a website which delivers dominantly static content(read: for a .edu website). (While this is the main thrust for this question, I am definitely interested in the non-static case as well since I may at some point soon "need" to deal with sessions and user login events etc)
The pattern I have often seen used for PHP (and other languages like Coldfusion, .NET, etc) is as follows:
// define header stub in header.php
<!DOCTYPE html>
<html>
<body>
<div id="headerWrapper">
<!-- header content goes here -->
</div>
<div id="contentWrapper">
// end header stub
// define footer stub in footer.php
</div><!-- end contentWrapper -->
<div id="footer">
<!-- footer content goes here -->
</div>
</body>
</html>
// end footer stub
To use this pattern, I would define a content file thusly:
// define content stub in contentFile.php
<?php include("header.php") ?>
<p>hello world</p>
<!-- other content goes here -->
<?php include("footer.php") ?>
// end content stub
I am looking for more. The problem I have with the above example is the level of coupling required by the general pattern. That is, there are some significant dependencies between header.php and footer.php for example (namely page structure, the dangling contentWrapper div tags, and, on a lower level, the inevitable css and js includes that are not required by every page). I am looking specifically for encapsulation. My ideal content page would look like this:
// ideal.php
<?php
$someObj.pageTitle="My First Page!!!";
$someObj.headInclude("/css/960.css");
$someObj.headInclude("/js/myFancyThing.js");
$someObj.preferedTemplate = "default"; /* or maybe "MathDept" or something like that */
?>
<!-- page content goes here, just semantic and structural markup, let the
template handle H1 and Paragraph formatting :) -->
// end ideal stub
This last pattern is something I would very much like to see. It seems to me a much more elegant solution for the decoupling of content from presentation. I don't know how to articulate this in PHP but I suspect it is feasible. Any help would be most appreciated! Thank you!!! :)
/* I hope what I have asked is appropriately scoped and titled. Please forgive me otherwise; I am still a bit green with Stack Exchange, PHP and pretty much everything lol */