Forum Moderators: coopster

Message Too Old, No Replies

PHP Template - flawed logic

         

Spook

5:30 pm on Apr 19, 2005 (gmt 0)

10+ Year Member



Hi All.

I seem to be making hard work of this somehow, hope someone can help.

I am developing a php site template. A single index page and the content changes depending on which link is clicked - pretty standard stuff I think and that part works quite well. However, at the begining of each content page I intended to store the relevant $title and $keyword information, such that header info will change to include these. Following is the basis of my template page [index.php]. page1.php would include the $title and $keyword variables. I have removed as much irrelevant code [banner, footer, sidebar etc.] as possible.

<?php
$page = ($_GET['page']);
if (empty($page))
{
$page = 'includes/content/page1.php';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title><?php echo $title;?></title>
<meta name="keywords" CONTENT="<?php echo $keywords?>">
<link href="./styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main">
<div id="content">
<?php
if(file_exists($page))
{
include ($page); // Page content
}
else
{
echo "Page temporarily unavailable";
}
?>
</div><!--end content-->

When the links on the page are clicked, the content changes but the title and keywords remain blank.

Can someone point out the flaw in my logic, or is there a better way to do this?

Many thanks in advance.

jamie

6:00 pm on Apr 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi spook,

you have not included the file in any way before you try to echo out the title and keywords.

you need to put the include statement above the html output

if(file_exists($page))
{
include ($page); // Page content
}

<html>
...

and as long as you have assigned the $title and $keywords variable it should echo it out correctly.

to echo out the content in the correct place, assign your content to a variable in the page.php

e.g.

$content = '<p>hallo buy my widget</p>';

then echo $content between the body tags, just like the title

hth

Spook

6:21 pm on Apr 19, 2005 (gmt 0)

10+ Year Member



Thanks jamie.

I knew I was making heavy going of it, but I couldn't see where for the life of me!

I was confusing include and echo statements.

What a plank!

Thanks again.