0

is there an HTML non-php way of calling to a file? For example, I am working on a large site that I don't want to have to edit each page when I want to edit the menu, footer, etc. Sort of like how wordpress uses php to include the header/menu data, I'd like to have one file to edit, but without using php. I don't know how possible this is. I am developing the site with HTML5/Bootstrap/JS and would like to avoid php if possible!

amphetamachine
  • 23,162
  • 10
  • 51
  • 68
  • 2
    This has been answered here http://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file – Arlind Apr 08 '15 at 22:59

3 Answers3

1

One method you can use is the .shtml file extension.

It also has SSI capabilities and is server-side, not client-side, therefore it runs off the server.

Server Side Includes (SSI)

Basic syntax to include files is:

<!--#include virtual="/footer.html" -->
<!--#include file="footer.html" -->
<!--#include virtual="/cgi-bin/counter.pl" -->

You can also include other files inside included files.

For example, say you have a header file <!--#include virtual="/header.shtml" --> and you want to include a navigation bar, you just do

header.shtml would contain <!--#include virtual="/nav.shtml" -->

all inside the same file, say you call it index.shtml

index.shtml would contain this structure

<!doctype html>
<head>
    <!--#include virtual="/js_files.shtml" -->
    <!--#include virtual="/metatags.shtml" -->
    <title>
    <!--#include virtual="/title.shtml" -->
    </title>
</head>

<body>
    <!--#include virtual="/header.shtml" -->
    <div>Hello world!</div>
    <!--#include virtual="/footer.shtml" -->

</body>
</html>

and inside <!--#include virtual="/header.shtml" -->

you could have this tag included in there <!--#include virtual="/nav.shtml" -->

containing

<a href="index.shtml">Home</a> - 
<a href="about.shtml">About</a> - 
<a href="contact.shtml">Info</a>
  • By using the same or similar structure for all your files, any change you make to one (include) file, will be affected globally throughout the site.

  • This is a method I use myself for certain websites where PHP isn't a requirement and have used for many years and works quite well, including Bootstrap-based.


References:

Funk Forty Niner
  • 73,764
  • 15
  • 63
  • 131
0

If your are already using java script lets just use JQuery

Using jQuery:

index.html:

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#header").load("header.html"); 
      $("#footer").load("footer.html");
    });
    </script> 
  </head> 

  <body> 
     <div id="header"></div>
     <div id="footer"></div>
  </body> 
</html>

header.html

<p><b> This is my header file </b></p>

footer.html

<p><b> This is my footer file!</b></p>
Odis Harkins
  • 292
  • 2
  • 13
0

You can use an iframe to include one HTML page inside another page.

Lie Ryan
  • 55,117
  • 12
  • 87
  • 139