PHP dynamic site template how to ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pauly
Forum Newbie
Posts: 4
Joined: Wed May 29, 2002 8:38 am

PHP dynamic site template how to ??

Post by pauly »

Hi all,

I'm trying to implement a PHP template system for my site however after reading through about 400 tutorials on this subject and posting in various forums I'm still having major league problems.

What I have so far is a main index page which contains the top section, the logo, the left hand side navigation, the right hand side and thr bottom section. I took out the three tables with the content in from the center and placed them in another file.

So the main index page is the actual template web page so all other pages will be built around this. I called it indexphp.php.

What I don't get is, the URL says http://www.domainname.com/indexphp.php?id=home

What the hell goes into the id file?

To test it I just put a simple hello text and saved it as id.html. Now when I typed in my url like the above one it loaded the actual indexphp.php webpage which was the actual template but instead of loading the home.html which contains the three tables and content which will go in the centre of the indexphp.php webpage it just loaded the id page which I had written hello in.

Sorry if this doesn't make much sense my brain is scrambled as I've been trying to get this to work now for a month and this is the best I can do :cry:

If someone could post an example or tell me what I'm doing wrong I would be eternally grateful as I can't find any more tutorials or anything and all my hairs falling out :?

PLEASE HELP SOMEONE :cry:

Paul
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

it sounds like your php script is still linking to the id.html file.

post the php coding that is supposed to load the home.html page and Im sure somewill will fix the error.
pauly
Forum Newbie
Posts: 4
Joined: Wed May 29, 2002 8:38 am

Post by pauly »

hi,

I'm not using a script, I don't think LOL.

It's like a tutorial which says to split the html code and site content and then where the content is do a <?php include ("$page.extension"); ?>

Then do as I described in my previous mail?

Aaaarggh - please help someone, this really sucks big time :cry:
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

You are using passing the page name to a variable called "id" to call the page. Unless you are reassigning it to $page.

Changing

<?php include ("$page.extension"); ?>

to

<?php include ("$id.extension"); ?>

or change the URL to http://www.domainname.com/indexphp.php?page=home

should sort out the problem.
pauly
Forum Newbie
Posts: 4
Joined: Wed May 29, 2002 8:38 am

Post by pauly »

Hi,

I'm still a bit stuck in the indexphp.php file I have,

<?php include ("id.html"); ?>

In that file I put hello, thats it nothing else no html or anything.

The IndexPHP.php file is going to be by main template file which contains the layout and html code.

Now I'm not sure if this is how people do it but for this page which will be my home page I also have some content on this in the center column in three tables. I've removed the center column and all html and put it in a file called home.html

I still don't get what to do with the file id.html though?

The way I am seeing it is that when someone clicks my domain the indexphp.php file is loading, it then loads all the html from that file which is the template for the site. It then reaches the PHP include statement mentioned above and loads up id.html.

What I want it to then do is load up the the rest of the center tables and html code from the home.html file.

Then finally I want to set up the links so I can load in other html files from the links if you see what I mean?

I'm really sorry about this but I really do need all the help I can get on this?

I think my question is what goes in the id.html file?

Thanks for reading this and sorry for the long post.

Paul. :cry:
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

here is what I do personally - for HTML:


i make a file named "layout.php"

in it, i have my whole layout in html, and where i want the html to load i put:

<? echo "$content"; ?>

so it would be like:

<html>
<head><title>title</title></head>
<body><? echo "$content"; ?></body>
</html>

for a small example..

then i make another file called like "somehtml.php"

in it i have:

<?
$content = <<<HTML
<b>this is some html</b>
HTML;
include('layout.php');
?>

and then when someone calls up "somehtml.php" it would load the layout, and print out this is some html where i told it to.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

In your URL you had indexphp.php?id=home

So when indexphp.php gets called like that it creates a variable called $id, so you need some kind of logic processing

if ($id=='home'){
include('myhome.php');
}
else{
include('someother.php');
}

note: If you have a more recent install of php (4.2.x I think) then check your php.ini file for the register_globals setting if it is not on then you need to use a slightly different method to get at the variable $id

$_GET['id']

Read the Sticky topic at the start of this forum and

http://www.php.net/manual/en/reserved.variables.php[/url]
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

$_GET (PHP 4.1 or higher) or $HTTP_GET_VARS (PHP < 4.1) give you access to the variables in the query string of the URL so,

Code: Select all

if (isset($_GET&#1111;'id']) && $_GET&#1111;'id']=='home')&#123; 
    include 'myhome.php'; 
&#125; else &#123; 
    include 'someother.php'; 
&#125;
Mac
Post Reply