Skip to content Skip to sidebar Skip to footer

Html Include: Separate Header And Footer

Can we include an HTML file / snippet from another HTML file? My use case is related to how a website is built; in a simple form, a site typically has the same header and footer ac

Solution 1:

What you're looking for is Server Side Includes. It used to be available on most hostings, no idea what the situation is today.

Actually, a simple system based on a makefile and, why not, php's command line version, might also be helpful: a simple makefile that visits all php files in a directory, feeds it to php (eg, processes page decoration and stuff) and redirects the output to a corresponding html file should be enough to generate a set of uploadable, 100% static html files.

Solution 2:

SSI is a great option if it is available to you as already suggested, I have always used PHP personally but as PHP is not available and if SSI isn't available then there is a JavaScript option as well.

The great thing with the JS option is the server doesn't need to have support for it due to the include scripts being client side. The bad thing is if the client doesn't have JS enabled in the browser the includes won't work. In saying that the vast majority of website users have JS enabled and this is displayed by most websites in the world who employ JS in 1 way or another.

Examples, the first one I found with a 2 second Google uses jQuery, have a look at the info here There are also some AJAX plugins that could potentially be used for this at the jQuery website if it is a path you're interested in going down.

I hope this helps you :-)

Post a Comment for "Html Include: Separate Header And Footer"