Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have just been handed an old html web site to update (not upgrade!).
I am not in a position to rewrite the whole thing which would have been my preference!

What I have been asked to do is add a new option in the menu which appears at the top of every page (40 of them) in the site.

Currently the html to build the menu is hand coded in every page!

Is there a way to use the equivalent of php's include in raw html?

I came across
HTML
<!--#include virtual="/menu.shtml" --> 
but cannot seem to get it to work; not sure which browsers support it anyway.
Surely there is a way to do this? I don't want to amend 40 pages it's boring!

I think the site will need another menu option soon so I would rather find a way to embed html now.

Help...

What I have tried:

I have tried using #include but with no success
Posted
Updated 8-Aug-16 5:55am

There is no include support with HTML.

Some HTML editors support there own way of doing this with special commands placed inside comments and replacing the content upon saving. But this will not help you with your current task because you have to edit all files at least once and must always use the specific editor later.

But you might use a text editor that provides search and replace for multiple files (all opened or all matching within a directory). With such an editor search for the existing menu entry code just before or after the new entry and replace with the old code followed / prefixed with the new one. Try first with a single file opened in the editor and check the result before applying to all files because most editors does not support undo for operations on multiple files.

[EDIT]
An editor that provides such operations is Notepad++.

You mentioned SSI (Server Side Includes). These are handled (as indicated by the name) by the web server which will load the file content (or variable contents or the output of an script) when delivering the page content. It must be enabled by web server configuration and the HTML file must be executable (by file system bit or using a specific extension). It will not work for local files loaded with the browser, requires to be supported by the web server, and requires access to the web server configuration.

So you might use it if you are in a position to change the web server configuration.
[/EDIT]
 
Share this answer
 
v2
Comments
dnibbo 23-Feb-16 8:05am    
Appreciate your time but... are you sure?
There is the wiki article (link below!) which I must confess I cannot get working but the page infers that it is possible.
Jochen Arndt 23-Feb-16 8:12am    
You asked for HTML. SSI is not HTML; it is a web server feature.

Read the Wiki link and the documentation of your web server to know if SSI is supported and how to use it.

Then enable SSI in the web server configuration, edit your HTML files and save them as .shtm[l] or set the executable bit.
dnibbo 23-Feb-16 9:33am    
Sigh
Just for info. It is supported. I started writing a new website and tried the include again and it works just fine.

Syntax I used is
<!-- #include file ="/commonHTML/header.html" -->

Where commonHTML is a project level folder.

You can even embed includes within includes if you feel the need.
I have embedded JavaScript in one also where the JavaScript only applied to the HTML in that include file so it only loads on pages that need it.

I have tested it on several platforms using several browsers and all seem to support it just fine so I assume that the include is performed on the server and therefore all pages are rendered as normal.
Not sure why my original test failed? It may be an IIS setting or something in the App Pool who knows / cares; it works! Yipee
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900