Page 1 of 2
Design on the server's side.
Posted: Wed Sep 19, 2007 8:37 pm
by figaro11
Hi, I don't know if anyone's going to be able to understand this, but I'll still try.
How do I design web pages without having to write the same code or layout over again? It seems like on every website there is usually a header and a footer that are always the same; consistent throughout the website. How do they accomplish this without having to copy and paste the same header and footer on every page?
I'm assuming it's a php, or other server-side language, solution. But please explain the methodology most server-side developers use construct their pages, if you will. Go wild with detail if you'd like.
Thanks.
Posted: Wed Sep 19, 2007 8:49 pm
by John Cartwright
Moved to PHP-Code.
Posted: Wed Sep 19, 2007 9:22 pm
by feyd
Templates.
Posted: Wed Sep 19, 2007 10:36 pm
by Christopher
You might want to start by learning about the PHP include() command. That will give you a start at combining common parts of pages with the page content.
Posted: Thu Sep 20, 2007 2:12 pm
by figaro11
I'm aware of the include function and am using it for my projects.
Feyd's comment seems interesting. But my concept of the word templates often makes me think of a css template. If your meaning something else could you elaborate more, maybe?
My current methodology is using the include function to piece together all the chucks of code into one page.
But this posses some problems. Let us say that I have a header.php file which holds all the external scripts and css tags in the head tag. Also, header.php would hold a navigation menu, logo, etc. Then the index.php file would include header.php at the beginning and then add some homepage content then include a footer.php page to the footer.
This seems good. But the problems I'm having with this is that I have multiple body tags. This problem can easily be fixed by not ending the body tag in the header.php file and not beginning the body tag in the footer.php file. My question on this problem: is there a better way?
My other problem is that I don't have control over the title tag for each page that includes the header.php file. Because it's in the header.php file that has the head tag which has the title tag. If I where to include both a head tag and a title tag in the index.php file then this might cause some problems if I'm in standards mode and it might not comply with web standards.
There. Hopefully I was able to express my problem; I have a hard time doing that.
Posted: Thu Sep 20, 2007 4:53 pm
by feyd
Templates, as in
Template Lite,
Smarty, et al.
Posted: Thu Sep 27, 2007 1:30 pm
by figaro11
I took my time looking into it. This is very useful. Thank you feyd.
Although, I might use this in later projects, currently I'm just using the include function. But the biggest problem I'm having with include() is the disability to change the title of my pages. I include
header.php, which writes the DTD, includes scripts and stylesheets, and also a <title> tag. I do believe that the title element can only be written once. So I can't change the title from what
header.php states it to be.
So my questions are: If I include a header.php, which has all the head part of the document, then how do I change the title, for different pages? And can I write multiple html, head and body tags in my markup with an XHTML Transitional document type; would it be valid standards?
Posted: Thu Sep 27, 2007 1:48 pm
by John Cartwright
The idea is that you compile your template into a single template at runtime (header, content, footers).. then make the appropriate string replacements.
Posted: Thu Sep 27, 2007 2:08 pm
by pickle
Set a variable in your main file, then reference it in your include file:
Code: Select all
<?PHP
$title = "This is my page. Bask in its glory";
include 'header.php';
?>
Code: Select all
<?PHP
echo <<<PAGE
<html>
<head>
<title>
$title
</title>
</head>
<body>
...
PAGE;
Posted: Thu Sep 27, 2007 5:02 pm
by figaro11
pickle wrote:Set a variable in your main file, then reference it in your include file...
Hey! Thanks.............. Why didn't I think of that?
This creates a Big Bang in my head! Now all I need to do is create a function that can do this for me.

Posted: Thu Oct 04, 2007 4:02 pm
by figaro11
Btw, who all here uses templates, raise their hand?
Posted: Thu Oct 04, 2007 4:07 pm
by pickle
Posted: Thu Oct 04, 2007 4:19 pm
by figaro11
pickle wrote:
I prolly have to be a bit more specific. Who here uses Template Engines?
Posted: Thu Oct 04, 2007 4:26 pm
by pickle
Posted: Thu Oct 04, 2007 4:33 pm
by figaro11
pickle wrote:
Oh yeah, Which one?
