Forum Moderators: coopster
would be much appreciated.....
thanks :)
melissa
[edited by: melissachan at 9:45 am (utc) on Nov. 7, 2003]
I notice one template system in particular that is mentioned quite often on this board called Smarty [smarty.php.net] that you may want to have a look at.
Basically, put your header, footer and navigation stuff in separate files and include them on the page. With creative CSS, you can have it display in any number of ways.
The next step up would be a template file that includes the header, footer, navigation and the content for that particular page. You can do that crudely but easily with URLs like
www.domain.com/template.php?page=page1
Then your template would be
template.php
<?php
include('header.php');
include('navigation.php);
include($_GET['page']."php"); //include the file named in URL with page=page1, minus the extension so you can use whatever you want.
include('footer');
?>
So many possibilities to get fancier and fancier, but that might get you started.
what is the purpose of?page=page1 in the URL?
First, I'm going to make this quite verbose, since as I understand you are a beginner. Apologies for being longwinded if you are a programmer who is merely a beginner at PHP.
This is known as a "get" parameter and it sends the info to the server at the time the url is requested. PHP grabs this info and puts it in the "superglobal" array $_GET, which is predefined in PHP. "Superglobal" means the information is available to you everywhere in your script without any additional action on your part. So in the example I gave
www.domain.com/template.php?page=page1include($_GET['page']."php");
1. You have the superglobal $_GET. This an array that PHP provides (you said you were a total beginner. Do you know what arrays are yet? If not, consult [php.net ]).
2. The superglobal $_GET array is an associative array with elements named for each GET parameter. In this case there is only one and it is referenced by the name "page". You access its value as $_GET['page'].
3. $_GET['page'] has a value of 'page1'. This is a string [php.net].
4. Then, you take that string and use it to figure out which file to plug into your template. In this case, 'page1' plus whatever extension you have. So if the file is named 'page1.php', you would concatenate the extension onto it like so: $_GET['page'] . "php"
$pagefile = $_GET['page'] . "php";
in this case, this is the same as
$pagefile = "page1.php";
So when you plug your data into your template,
include($_GET['page'] . "php");
includes that file and plugs it into the template.
Tom
havent checked this forum in awhile.
Shame on you! Don't you know it's the best forum on the web? With regard to the first part, I'm just kidding, of course, but I should say WELCOME, since I see you're new.
With regard to the second part, I believe it to be true, and not just for web stuff, but for everything. It's pretty much the only forum I'll read these days - flame wars and insults not allowed. Everyone welcome. Some folks so smart it makes your head spin. I don't think you'll find such a helpful and polite group anywhere on the web!
Tom