moey
moey

Reputation: 10907

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 across the board. It is pretty straightforward if the site is equipped with e.g. PHP so you can do something like the include statement; we can contain the header and footer in separate files and include them later. But, what if the site is purely static i.e. no "back-end" support?

One thing that I had done in the past is to utilize templates in Dreamweaver. This worked but I'd prefer something that is more product-independent.

Thanks.

Upvotes: 2

Views: 5484

Answers (2)

Ryan
Ryan

Reputation: 1888

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 :-)

Upvotes: 0

fvu
fvu

Reputation: 32973

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.

Upvotes: 3

Related Questions