[web] External HTML Files

Started by
7 comments, last by igni ferroque 18 years, 4 months ago
I have a menu system that uses &#106avascript heavily and is a large bit of code. And every webpage is going to use this menu. So instead of inserting it in the html code for every page can I have maybe some sort of external html file. Sort of like a .js file. Or if my code uses a href tags and div tags would I be able to use document.write with &#106avascript and still be able to use css. So then I maybe be able to keep the menu in another file.
Advertisement
Do you have any sort of scripting support? If you have php support it is as easy as.
<?php    include "file.htm";?>
If you don't have PHP support you can use Apache's Server Side Includes (shtml files). See this page.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

sadly I dont everything must be ran off of a cd. And the person who is using the cd probably didnt install php on their computer.
If it's going to run off a CD, you could still write a program which will process the includes once, and use that the generate the pages which you'll use on the CD at runtime.

Then you'll only have to maintain the menu once regardless of how many times it will appear.

Mark
Quote:Original post by Supaflyfrank
sadly I dont everything must be ran off of a cd. And the person who is using the cd probably didnt install php on their computer.
Keep in mind that most Windows XP installations prohibit scripts to run from the local filesystem.
Quote:Original post by markr
If it's going to run off a CD, you could still write a program which will process the includes once, and use that the generate the pages which you'll use on the CD at runtime.


Bingo.


Grab a copy of M4, rename your files from .html to .html.in, then create a macro definition file containing something to the effect of:
define(`HTML_MENU`, `     menu item 1    ')


Then put the string "HTML_MENU" in your HTML files where you want the menu to appear, e.g.:
HTML_MENU<div id="content">   



Then run m4 with:
m4 menu.m4 myfile.html.in > myfile.html


The result is a file called myfile.html with the menu inserted. You might want to keep the input files in a separate directory so they don't get included on the CD.

It's pretty easy to figure out. Be sure to keep the manual handy, and make sure you read through the first three sections to begin with. It'll take about 10 minutes at the most.

If you need something more powerful, look into Apache Forrest.
Free Mac Mini (I know, I'm a tool)
doing so will it cause the html file being included anyway? I am trying to seperate it to save from downloading the same code over and over again. So will it just cause the code to be copied to the new file?
Nevermind. The answer is much simpler. Put the &#106avascript in a separate file and put a script tag pointing to that file where you want the menu. E.g.:
<script type="text/&#106avascript" src="mymenu.js"&gt;&lt;/script&gt;<br></pre>You might still want to eventually look into <a href="http://forrest.apache.org/">Apache Forrest</a>.
Free Mac Mini (I know, I'm a tool)

This topic is closed to new replies.

Advertisement