Click to See Complete Forum and Search --> : Taking HTML code from a different file


JoelC
04-19-2006, 01:33 PM
There's this website I'm building (http://www.fuzzit.com/rcta).

The website is basically a table. It has a header area with the site's banner and links to different pages. An ending area where theres a picture closing the table (design wise). And finally an area between the header and the ending, where the pages are shown.

My problem is that on each page I have to write out the entire code (Copy and Paste, but still), which:
a) Makes my code hard to follow.
b) Leaves me with the same code over and over again.
c) Makes it rather hard to change links or images, since I have to do each page individually.

I was wondering if there was a way that I could insert the header and ending codes from a different file, so it would come out:

<body>
[header insert]

whichever page code I'm working on

[ending insert]
</body>

This way my code would be much easier to follow and work on, and much nicer to look at ;)

I'm sure there must be a way to do this, so if you could clue me in, I'd really appreciate it.


Thanks,
Joel.

TiGGi
04-19-2006, 01:41 PM
solution is "includes", pretty much every serverside language has it. So the question is what serversides do you have avaialble to you (coldfusion, php, asp, .net..)?
Name tells it all, it includes a page into the page.
on coldfusion would look something like this: <cfinclude template="page.cfm> so where u place that code it would include body from the other page!

the tree
04-19-2006, 01:46 PM
You appear to have PHP 4.0.1, this is easily enough. Try creating a file with a .php extension and putting this in.<?php include 'header.txt'; ?>Easy huh?

JoelC
04-19-2006, 01:52 PM
Didn't think it wouldn't be :)
I'm afraid that I'm not very programming-savvy when it comes to server side languages. I know HTML (and some basic CSS that I picked up this week) but that's pretty much it.
So I may sound like a fool when I ask this: Can I just use PHP on my computer while working on it without downloading any software?

EDIT: Never mind, I've downloaded PHP 5.1.2 and have yet to see it work

EDIT 2: No idea what I'm doing, any tips?

yet another EDIT: I had an IIS directory left over from some test with ASP (A friend set it up) so I just put all my files in that wwwroot directory. It works, thanks a lot, I'll just have to learn how to use serverside languages now, I guess.

TiGGi
04-19-2006, 02:08 PM
you don't have to install php on your pc. Your hosting company has it so when you create your files just upload them to your server and test it. Just make sure you save them as .php not .html

pcthug
04-20-2006, 02:43 AM
I would personally use PHP includes (http://www.php.net/include/):

<?php
//This will include a file named example.txt
include 'example.txt';
?>

Then simply save your page with a .php extension.

Another popular include method is SSI(Server Side Includes):

<!-- This will include a file named example.txt -->
<!--#include file="example.txt" -->

Then simply save your page with a .shtml extension.

And that's all there is too it. But remeber, for your server to interperet these scripts it'll need the appropriate server-side languagues installed and enabled.