Include

liunx

Guest
I am wondering about using an include for header code which will be used on a number of pages. <br />
<br />
Currently I have it coded like this: On each page, I have the following call to an include file which runs the code in the include file;<br />
<br />
<SCRIPT LANGUAGE="javascript" SRC=http://www.webdeveloper.com/forum/archive/index.php/"Header.inc"></SCRIPT><br />
<SCRIPT LANGUAGE="javascript"><br />
<!--<br />
//Call function to build the page header.<br />
WriteHeader()<br />
--><br />
</SCRIPT><br />
<br />
Then on the header include file, I have the following:<br />
<br />
function WriteHeader()<br />
{<br />
var strHeader = "<div align='center'>"<br />
strHeader += " ..." <br />
<br />
and so on with the code<br />
<br />
document.write(strHeader)<br />
}<br />
<br />
This works, but I am wondering about using JS. Is there another way to do this without using JS? I tried <!--#include file="header.html" --> calling header.html with the code to run the header, but couldn't get it to work. I don't know exactly where the include code is supposed to go or if it matters.<br />
<br />
Can someone tell me the easiest and most efficient way to do this please, whether it's one of the above methods or something else.<br />
<br />
Thanks very much.<!--content-->What server side languages do you have?<br />
<br />
<!-- m --><a class="postlink" href="http://forums.webdeveloper.com/showthread.php?s=&threadid=8760&highlight=server+side+include">http://forums.webdeveloper.com/showthre ... de+include</a><!-- m --><br />
<br />
may help<!--content-->JavaScript is working fine, but I am just wondering if that is the most efficient way to do this? <br />
<br />
I can use ASP no problem. I tried SSI, but with no luck. I guess it's not enabled here. I will have to check with the network guy. The other thing is that this is not where the site will be posted. It will be on a government server and I will have to check to see about the server-side languages.<br />
<br />
The following scripting languages are what they have listed for us to use. We may be able to use others, but would have to ask for permissions to do so, and then wait and see.<br />
<br />
ASP<br />
PHP<br />
Perl (Server-Side): Perl 5.0<br />
JavaScript (Client-side: JS 1.0, 1.1, and 1.2.<br />
<br />
I have no prior experience in Perl or PHP.<br />
<br />
Do you think the way I have it coded right now is fine, or would one of the other ways you mentioned be better?<br />
<br />
Thanks again.<!--content-->anyhtmlfile.shtml:<br />
<br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"<br />
"http://www.w3.org/TR/html4/strict.dtd"><br />
<html><br />
<head><br />
<title>An SSI tutorial</title><br />
<meta http-equiv="content-type"<br />
content="text/html; charset=iso-8859-1"><br />
</head><br />
<br />
<body><br />
<!--#include virtual="header.html"--><br />
<div id="contents">...</div><br />
...<br />
</body><br />
</html><br />
<br />
<br />
And your header.html<br />
<br />
<div id="header"><br />
<img src=http://www.webdeveloper.com/forum/archive/index.php/"logo.gif" alt="My Site" width="200" height="50"><br />
</div><br />
<div id="toplinks"><br />
<ul><br />
<li><a href=http://www.webdeveloper.com/forum/archive/index.php/"link1.html">Link 1</a></li><br />
...<br />
<li><a href=http://www.webdeveloper.com/forum/archive/index.php/"linkn.html">Link n</a></li><br />
</ul><br />
</div><br />
<br />
<br />
NOTE:<br />
1. the extension of the file that has SSI is ".shtml"<br />
2. <!--#include virtual= is used instead of <!--#include file=. This is because if file is used, your included file should be in the same directory... with virtual, you can give path to the included file, which may or may not be in the same directory.<br />
3. The code from header.html will be included as-is (sic) in the parent file. Hence header.html does not contain <html>, <head> or <body> tags.<br />
4. You need to have perl on your server for SSI to work (double check someone plz on this)<!--content-->4. You need to have perl on your server for SSI to work (double check someone plz on this)Perl and SSI are two unrelated technologies. Neither is required for the other to work.<!--content-->I did get it working after. Thanks. I named my include file header.asp. In my default.asp page, I use <!--#include file="includes/header.asp" --> to call the include file.<br />
<br />
Should I use virtual instead of file?<br />
<br />
Also, I put the opening html, header and opening body tags in the header.asp include file. Is this ok? I created a footer.asp include file which will store all footer material and </body> and </html>. Both are called from default.asp and I will put the rest of the code for the page in between these 2 calls.<br />
<br />
I checked with the network guy and he said that SSI is enabled to run on the server. I am wondering though, is this a setting that would have to change on different servers? I am running IIS 5.0 at home, but haven't tried this project there yet? Is there anything specific I would have to do to be able to run SSIs?<br />
<br />
Thanks again!<!--content-->
 
Back
Top