Inclure un fichier html dans un autre

It’s very common practice to have a consistent theme on a web site. You might have a standard navigation bar or a logo or even just a page footer with copyright and administrative information. Rather than actually having that information on each and every page it would certainly be nice if you could write your navigation bar once, keep it in one file, and then reference that file in each of several different pages. Make a change to the navigation bar in one place and instantly all pages are updated.

Welcome to “include” files – an incredibly powerful facility that can do this, and so much more, on your web site.

Includes break down into two categories: client and server. A “client” side include is one performed by your browser. Unfortunately, there is no specific syntax in HTML for client side includes so we have to play a small game using javascript. A “server” side include is exactly that – the include happens on your web server so the client browser never even knows it happened.

Server Side Includes

We’ll start with the conceptually easier one: the server side include. The specific syntax will vary based on what type of server you have and what language your pages are written in.

Simple HTML pages on most common web servers can use a syntax called Server Side Include, or SSI. As an example in an HTML file a.html we can place this line:

<!--#include FILE="b.inc" -->

The page seen by a browser viewing a.html will consist of the contents of a.html before the include line, followed by the contents of b.inc, followed by the contents of a.html after the include line. Put the HTML for your navigation bar in a file like b.inc, and all your pages can show the exact same bar.

SSI is available on both Apache and Microsoft IIS web servers. On Apache some configuration may be needed but even if you don’t have access to the actual server configuration files it can typically also be enabled by commands in a file named .htaccess that you will either find or can create in your server’s web directory. Under IIS, SSI is enabled anytime you use “.asp” pages — so the only configuration you need do is to name your pages .asp instead of .html.

 

extradrmtech

Since 20 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions. I am an experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. When not writing code, I like to dance salsa and swing and have fun with my little family.

You may also like...

Leave a Reply