I'm building a very big website, and for the PHP+XHTML documents, I use a template. For example (highly simplified):
home.php:
include template.php
function mainContent() {
echo('content here');
}
template.php:
echo('<html><head><style type="text/css" src="style.css" /></head><body>');
mainContent();
echo('</body></html>');
On the other hand, we use this approach where I work:
home.php:
include template.php
header();
echo('content here');
footer();
template.php:
function header() {
echo('<html><head><style type="text/css" src="style.css" /></head><body>');
mainContent();
}
function footer() {
echo('</body></html>');
}
The first approach is a lot nice imo, but in some cases I have to selectively include template.php where some executions of the script result in new header information being sent. This results in code repetition (having to add "include template.php" in multiple places) and hard to read code.
Are there any other ways of doing it beside these?
Thanks