
Originally Posted by
stereofrog
You can replace that with this:
PHP Code:
$layout = "layouts/main.php";
ob_start();
$handler();
$content_for_layout = ob_get_clean();
include($layout);
With the main template:
HTML Code:
<html>
<body>
<?php echo $content_for_layout ?>
</body>
</html>
And the news template:
HTML Code:
<h1>news</h1>
...
Note that the template can define variables too, so if it wanted a specific layout file it could set $layout itself. (Or call a function to set that if you want a little more abstraction.)
Douglas
The code so far:
index.php
PHP Code:
<?php
function handle_default() {
handle_news();
}
function handle_news() {
$news = get_all_from_db("SELECT * FROM news");
include "templates/news.php";
}
function handle_profiles() {
}
function handle_links() {
}
function handle_help() {
}
$content = @$_GET['content'];
$handler = "handle_$content";
if(!function_exists($handler)) {
$handler = "handle_default";
}
$layout = "layouts/global.php";
ob_start();
$handler();
$content_for_layout = ob_get_clean();
include($layout);
?>
layouts/global.php
HTML Code:
<html>
<head><title>A Website <?php echo $page_title ?></title>
<!-- other junk and css goes here -->
</head>
<body>
<!-- header -->
<!-- body -->
<?php echo $content_for_layout ?>
<!-- footer -->
</body>
</html>
templates/news.php
HTML Code:
<?php $page_title = 'News' ?>
<h1>news</h1>
...
Bookmarks