Help - Search - Members - Calendar
Full Version: Duplicating HTML CODE
HTMLHelp Forums > Web Authoring > General Web Design
ryan_acc
Hi all,

I am having trouble developing my new website.

I am a Novice but capable of understanding basic CSS and HTML and have used some JAVASCRIPT but don't really know how to use it.

The problem I have is this:
I have created a drop down menu at the top of my page which links between all other pages (30 at present). I have used html to add the actual fields ie. <tr><td class="menu"><a href="../indianrainforest">Indian Rainforests</a></td></tr>

However every time I add a new page and add <tr><td class="menu"><a href="../niagara">Niagara Falls</a></td></tr> to the drop menu I have to go to all 30 other pages and add the new code to each drop menu. This is barely manageable now never mind when it is possibly linking 100 pages.

Therefore I ask is there a way to set a code on one of the pages that will automatically add this new code to all the pages. ie. maybe only having this code being written on one webpage but being accessible from all of them:
<tr><td class="menu"><a href="../indianrainforest">Indian Rainforests</a></td></tr>
<tr><td class="menu"><a href="../niagara">Niagara Falls</a></td></tr>
<tr><td class="menu"><a href="../taj">Taj Mahal</a></td></tr>
<tr><td class="menu"><a href="../liberty">Statue of Liberty</a></td></tr>


I have been using CSS to apply changes to all webpages in terms of functionality and appearance but I don't know if there is anyway to add content like the above code to apply to all pages:

table{font-size:150%;background:white; border:5px groove #37B63A;}
a{color:white;text-decoration:none;font:bold}
a:hover{color:black}
td.menu{background:#AFE0B0}

table.menu
{
font-size:60%; background:black; border: 2px solid #37B63A;
position:absolute;
visibility:hidden;

}

Any suggestions would be greatly appreciated

Ryan
Darin McGrew
Please see the FAQ entry How do I include one file in another?
ryan_acc
QUOTE(Darin McGrew @ Jun 17 2009, 04:58 PM) *

Please see the FAQ entry How do I include one file in another?


That looks like the answer but I am trouble getting it to work.

What I have done is created a new folder called drop with: drop.html
In the folder I have the code necessary for the drop menu.
Then on the original folder where the code would be place I have put: #include "drop.html"

Will this only work online or am I not setting it right or something. The above code looks like CSS, should I put it there?

Thank you

Ryan
Darin McGrew
Server-side includes require a server to work. They also require that the server is configured to process SSI directives in your documents.
pandy
When you upload the stuff to your host, name the INCLUDING file .shtml and the INCLUDED file .txt (or for example .inc if you want). It will work if the included file has an html extension, it's just neater if it doesn't.

Most servers are configured to parse .shtml files for SSI, provided SSI is available. You can change that behavior later so you don't have to rename all files, but test that it works first.

QUOTE(ryan_acc @ Jun 18 2009, 07:39 PM) *

Then on the original folder where the code would be place I have put: #include "drop.html"


That isn't literally what you wrote, is it? blink.gif
ryan_acc
QUOTE(pandy @ Jun 18 2009, 08:01 PM) *

When you upload the stuff to your host, name the INCLUDING file .shtml and the INCLUDED file .txt (or fr example .inc if you want). It will work if the included files has an html extension, it's just neater if it doesn't.

Most servers are configured to parse .shtml files for SSI, provided SSI is available. You can change that behavior later so you don't have to rename all files, but test that it works first.

QUOTE(ryan_acc @ Jun 18 2009, 07:39 PM) *

Then on the original folder where the code would be place I have put: #include "drop.html"


That isn't literally what you wrote, is it? blink.gif


I think you are giving me more credit than I'm due.

So are you saying that I should re-save all my pages as .shtml instead of html?(confused) Then upload to the host server.

Then create another file called eg. drop.txt (with the required code I want to have on all my website pages) Then upload that to the host server.

At this point what code do I put to link the the pages?and where do I write it?

Thanks for your patience

Ryan
pandy
Nah, I'm saying you should test if SSI works first. Create a test page and name it for example test.shtml. Put some SSI directive in it. Upload it to your server then go there with a browser and see if it works. Doesn't need to be an include. Use the below. If you see the tag replaced with some text it works.

CODE
<!--#echo var="DOCUMENT_NAME" -->


If that works we can go on to how to make the server do this with .html pages. wink.gif

QUOTE
At this point what code do I put to link the the pages?and where do I write it?


The SSI "tag"? You put it where you want what it returns to appear. See it as Find and Replace, only the server does it for you. You just need to tell it what to look for.
richard.williams
Instead of using SSI (server side includes), I generate my web pages in the following way.

- I have my pages in /myproject/pages/*.html. Each page contains a marker "#include Menu" .
- I have the drop down in /myproject/include/Menu.html.
- I generate the resulting pages in /myproject/Release with the following biterscript.

CODE
# Script buildrelease.txt
# Get the contents of Menu.html.
var str menu; cat "/myproject/include/Menu.html" > $menu

# Get a list of .html files from pages folder.
var str list; lf -n "*.html" "/myproject/pages" > $list
# Process files in $list one by one.
while ($list <> "")
do
    var str inputfile, page, outputfile
    lex "1" $list > $inputfile; cat $inputfile > $page
   # Replace "#include Menu" with $menu in $page
   sal -c "^#include Menu^" $menu $page > null # We don't want to see the output.
                              # It will be written back into $page.
   # Make the output file name.
   sal -c "^/myproject/pages^" "/myproject/Release" $inputfile > $outputfile
   # Write output file with $page
   echo $page > { echo $outputfile }
done


I run the script from biterscripting with the following command.

CODE
script buildrelease.txt


That does it for me. Should work on any operating system and any version, including any Windows. biterscripting can be downloaded if necessary from http://www.biterscripting.com .

I have not tested this particular script - please test it. This script does not change any original pages, so it should be ok.

The scripts I use are slightly more advanced - I have various templates, common sections in /include/, individual sections in /sections/, etc. Works great for static content, but can also use similar methodology for run-time page generation, since biterscripting scripts can be run as part of the web server. Other scripting languages will work as well.

Richard

Frederiek
QUOTE
Should work on any operating system and any version, including any Windows.

Make that: ONLY Windows, as it's an .exe file.
kennyv
Ryan,

Have you considered using an iframe on each page for you menu? Just set drop.html as the src for the iframe.

It's extremely easy to do and when you update your drop.html it will affect all pages that have the iframe.

<div id="menu" style="height:nnpx; width:nnpx;">
<iframe src="drop.html" width="99%" height="99%" bgcolor="#ffffff" frameborder="0">
</div>
The "div" isn't necessary but gives you more control.

Ken
Frederiek
IIRC, when the dropdown menu is higher than the frame, it won't go over the edges of it.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.