Including one htm page in another, Headers and Footers |
Including one htm page in another, Headers and Footers |
ShadowyBob |
Oct 19 2006, 05:41 PM
Post
#1
|
Advanced Member Group: Members Posts: 101 Joined: 6-October 06 From: Peterborough, UK Member No.: 354 |
I'm fairly certain I'll get a negative response to this after browsing various help subjects, but just in case....
I have a number of pages that use a repeated header/footer. These headers and footers occasionally need updating and to avoid the tedious task of amending a lot of pages with the same amendment (and here I hang my head in shame) I use FP to allow me to include the header/footer as a separate document. As a result any amendments have to be done once only. Is there a pure htm/css way of doing the same thing? |
pandy |
Oct 19 2006, 05:59 PM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
No, only frames and that's not the way to go. You can easily do this server side though with SSI (Server Side Includes). I guess most programming languages available to you on the server can do it too, like for example PHP.
http://www.htmlhelp.com/faq/html/design.html#include-file |
ShadowyBob |
Oct 19 2006, 06:56 PM
Post
#3
|
Advanced Member Group: Members Posts: 101 Joined: 6-October 06 From: Peterborough, UK Member No.: 354 |
Thanks pandy, you're right - I avoid frames like the plague.
My problem, though, is that I get a cold sweat when I see you guys giving advice about using server-side languages. Way above my limited experience. (Although I do realise that by using FP, I am taking advantage of the server's ability to deal with FP!). And, yes, your link was one of the pages I had attempted to read before posting here. I think I got as far as the 2nd para before I realised I hadn't a clue what the words meant! |
pandy |
Oct 19 2006, 07:23 PM
Post
#4
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
You shouldn't be scared of that. You don't need to write a complete program. SSI for example isn't even a programming language. Not sure what it is, come to think about it.
All you need to do is place a special "tag" where you want a file to be included. Like this. <!--#include virtual="/path/to/file.ext" --> Not too hard, huh? SSI can do more than that, but that's all you need for what you want to do. You also need to make the server parse your HTML for SSI, either by renaming the files .shtml or by adding a line to the .htaccess file that makes it work for .html too (this is on Apache). |
ShadowyBob |
Oct 20 2006, 01:31 PM
Post
#5
|
Advanced Member Group: Members Posts: 101 Joined: 6-October 06 From: Peterborough, UK Member No.: 354 |
OK, pandy, I'm intrigued. Can you please keep it very simple while I build up a bit of confidence?
If I have a page called, say, main.htm and I want a header that is made up of header.htm in the same directory, do I understand that all I have to do, after the body tag in main.htm is type <!--#include virtual="header.htm" -->? Now, the bit I don't have a clue about is where you start talking about parsing etc.. And how do I know if I have to change the extension to .shtml or add a line to an .htaccess file (whatever that is)? I use Lycos to host my web site. All I know about them is that I can use FTP and Front Page to upload my web files and I use php and MySQL to host my forum. Thanks for your patience so far. Bob |
pandy |
Oct 20 2006, 02:03 PM
Post
#6
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
OK, pandy, I'm intrigued. Can you please keep it very simple while I build up a bit of confidence? If I have a page called, say, main.htm and I want a header that is made up of header.htm in the same directory, do I understand that all I have to do, after the body tag in main.htm is type <!--#include virtual="header.htm" -->? No. If you want to do it like that you have to use Include File. <!--#include file="header.htm" --> The difference is that Include File uses a path relative to the current document, as you are used to from HTML. But! Unlike in HTML you can't use it for a file ABOVE the current one in the file structure, i.e. you can't do "../blah/file.txt". So it's rather limited. Include Virtual takes a path from the document root, that's what the first slash refers too. The advantage is that the path will be the same no matter where the document in which you use it is. QUOTE Now, the bit I don't have a clue about is where you start talking about parsing etc.. And how do I know if I have to change the extension to .shtml or add a line to an .htaccess file (whatever that is)? I use Lycos to host my web site. All I know about them is that I can use FTP and Front Page to upload my web files and I use php and MySQL to host my forum. It's your choice. But if you are on Lycos free hosting you probably don't have a choice. Do they allow SSI? I know Angelfire does but they don't tell you. Angelfire and Lycos are the same, aren't they? You can easily check if it's on by default by uploaded a file with some SSI directive in it. Name it .shtml Try some of these. If they change to something else when you look at the page in the browser you are all set. CODE <!--#echo var="LAST_MODIFIED" --><br> <!--#echo var="DATE_LOCAL" --><br> <!--#echo var="SERVER_NAME" --> BTW, note the space before the "-->". |
pandy |
Oct 20 2006, 02:07 PM
Post
#7
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
Also, simply put parsing means that a programs goes through a document looking for something. In this case the server looks through the HTML for those special tags. When it sees one it replaces it with something else, for example the HTML from another file. It does all this before it serves the page to the browser. When you view source you see no trace of the SSI. If you do something is wrong.
|
Peter1968 |
Oct 20 2006, 03:06 PM
Post
#8
|
Serious Coder Group: Members Posts: 448 Joined: 23-September 06 Member No.: 213 |
For what Pandy described to work, your server must be configured for it.
Options + Includes must be usable by a user account, i.e you. You can add this line (Options +Includes) to a .htaccess just to make sure. Another line, usually in the server's .conf file is AddHandler server-parsed .shtml Again, you can add this in to your own .htaccess. Also, in a .htaccess file in your document root, you'll need to add the line AddType "text/html; charset=your-charset-here" shtml somewhere for the benefit of browsers not clued enough to deduce what a .shtml file is. Obviously replace the charset example I've given with your real charset. Note the quotes. They're needed. I heartily recommend you put the include files in their own directory in your doc_root (I use /inc) and link to them as <!--#include virtual="/inc/include.html" --> All up? In your .htaccess (in your document root) do: CODE Options + Includes AddHandler server-parsed .shtml AddType "text/html; charset=your-charset-here" shtml What's a .htaccess file? Better than I can explain it. http://apache-server.com/tutorials/ATusing-htaccess.html Perservere with includes, they're great and you'll wonder why you or anybody else ever uses frames, especially those with telnet/SSH access to their own server. |
pandy |
Oct 20 2006, 04:07 PM
Post
#9
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
He is using Lycos. Either SSI is enabled or it isn't. He can't use .htaccess files or make other changes to the configuration. All he can do is test if it works.
|
ShadowyBob |
Oct 20 2006, 05:06 PM
Post
#10
|
Advanced Member Group: Members Posts: 101 Joined: 6-October 06 From: Peterborough, UK Member No.: 354 |
Thanks pandy, it all works beautifully (and my Lycos a/c is a paid one, not a free one - I wish!).
I went away earlier and played and the virtual path worked fine, but only because I was dealing with files in my root directory. Thanks for pointing out the differences. Now I won't come screaming "it don't work in my other files!". Thanks also Peter1968, for your words of wisdom. I've now created my own .htaccess.htm file. Regrettably your link to apache-server seems to be down, so I'll have to try later. As an aside - to save me too much searching - is there a simple explanation for why I should have my charset set as either 'utf-8' or 'windows-1252'? I seem to have picked up both while designing my many pages over the years. The site is English, although I have a few pages that include other languages (i.e., languages as in the spoken/written sense not in the computing sense!). Generally I have used 'windows-1252' but 'utf-8' only where I have a mix of languages on the page, but cannot now remember why! As to 'includes', you're right - the possibilities now look very exciting. A couple of early thoughts: is it possible to use this technique within, say, table/cell elements (I'm thinking of a navigation panel down the side of a page contained in a table cell); and is the style for the included page taken from it's own css structure or the parent page's? Once again, many thanks to you both. Bob |
jimlongo |
Oct 20 2006, 05:08 PM
Post
#11
|
This is My Life Group: Members Posts: 1,128 Joined: 24-August 06 From: t-dot Member No.: 16 |
He said he uses a php forum. So wouldn't php include be easier? Just make your file index.php - that is unless you can add
AddType application/x-httpd-php .html in your .htaccess file or controlpanel, in which case you can call it index.html CODE <?php include( 'header.html' ); ?> i see as I was writing this you posted that you have been successful, so . . . nevermind . . . This post has been edited by jimlongo: Oct 20 2006, 05:09 PM |
ShadowyBob |
Oct 20 2006, 05:13 PM
Post
#12
|
Advanced Member Group: Members Posts: 101 Joined: 6-October 06 From: Peterborough, UK Member No.: 354 |
Thanks jimlongo, appreciated!
|
pandy |
Oct 20 2006, 05:20 PM
Post
#13
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
My bad. I didn't know Lycos had paid hosting and I missed that you have a PHP forum... jimlongo is right. If you already use PHP that's probably what you should use for this too.
QUOTE A couple of early thoughts: is it possible to use this technique within, say, table/cell elements (I'm thinking of a navigation panel down the side of a page contained in a table cell); and is the style for the included page taken from it's own css structure or the parent page's? You can use it anywhere and as many times as you wish. Think of it like this. You have a page. You take a pair of scissors and cut random pieces out. The server glues the pieces back again and the page looks whole. It doesn't matter where you cut. CSS works as if the page was one page. Which is exactly what it is when it reaches the browsers. The browser never sees the included files on their own. It doesn't know they exist. |
ShadowyBob |
Oct 20 2006, 06:16 PM
Post
#14
|
Advanced Member Group: Members Posts: 101 Joined: 6-October 06 From: Peterborough, UK Member No.: 354 |
Thanks again pandy. One final thought (I hope) on this subject. I'm happy with the shtml 'include' route as it's simple. Why move to php and complicate my life?
Re. the charset, I have since found the following to be very helpful: http://ppewww.ph.gla.ac.uk/~flavell/charset/checklist.html |
Darin McGrew |
Oct 20 2006, 07:03 PM
Post
#15
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
QUOTE I'm happy with the shtml 'include' route as it's simple. Why move to php and complicate my life? If SSI works for you, then there's no reason to switch to PHP. PHP can do things that SSI can't, but if you don't need to do those things... |
pandy |
Oct 20 2006, 07:18 PM
Post
#16
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
What Darin said. But if you already use PHP in some pages things become a little different. If the forum is the only PHP, you'll be fine.
|
ShadowyBob |
Oct 20 2006, 07:56 PM
Post
#17
|
Advanced Member Group: Members Posts: 101 Joined: 6-October 06 From: Peterborough, UK Member No.: 354 |
What Darin said. But if you already use PHP in some pages things become a little different. If the forum is the only PHP, you'll be fine. I think I get the picture, and yes, php is only used in the forum and that comes not from my expertise (apart from cosmetics), but from phpbb! Thanks all! |
Peter1968 |
Oct 21 2006, 04:41 AM
Post
#18
|
Serious Coder Group: Members Posts: 448 Joined: 23-September 06 Member No.: 213 |
He is using Lycos. Either SSI is enabled or it isn't. He can't use .htaccess files or make other changes to the configuration. All he can do is test if it works. Spot on Pandy *but* it's how enabled it is that's the rub. It's not enough to allow Options + Includes in the server's httpd.conf, the mime type and the handler need to be specified as well and I've seen configurations where it's simply been allowed, as you say, but not properly configured. This post has been edited by Peter1968: Oct 21 2006, 04:44 AM |
Christian J |
Oct 21 2006, 06:14 AM
Post
#19
|
. Group: WDG Moderators Posts: 9,658 Joined: 10-August 06 Member No.: 7 |
QUOTE I'm happy with the shtml 'include' route as it's simple. Why move to php and complicate my life? If SSI works for you, then there's no reason to switch to PHP. PHP can do things that SSI can't, but if you don't need to do those things...Correct, but what if the OP changes his mind in the future? OTOH if the OP already uses SSI there's no point in changing to PHP just for inclusions. In any case simple PHP includes are not more complicated than SSI (compare the code examples above in this thread), so you won't complicate your life by choosing PHP. |
pandy |
Oct 21 2006, 06:29 AM
Post
#20
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
Spot on Pandy *but* it's how enabled it is that's the rub. It's not enough to allow Options + Includes in the server's httpd.conf, the mime type and the handler need to be specified as well and I've seen configurations where it's simply been allowed, as you say, but not properly configured. No, it wasn't "spot on" at all. As said, I was under the impression the OP was on Lycos free hosting in which case he wouldn't have any control of these things. I was wrong. |
Lo-Fi Version | Time is now: 26th April 2024 - 02:11 PM |