CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   General web building (http://www.codingforums.com/forumdisplay.php?f=10)
-   -   What is the best way to include another html file? (http://www.codingforums.com/showthread.php?t=287173)

alank2 02-06-2013 03:36 PM

What is the best way to include another html file?
 
Hi,

What is the best way to include another html file such as a footer that is the same on all pages. I read about using a server side include, but is there a better way to do it?

Thanks,

Alan

SB65 02-06-2013 03:38 PM

No, server side includes is the best way - have a look at using PHP includes.

alank2 02-06-2013 03:56 PM

Hi,

Will a server side include when viewing a file locally in a web browser?

Thanks,

Alan

SB65 02-06-2013 05:22 PM

To use PHP it need to be running on a server for it to work. For local testing you can use something like xampp. This lets you install a server on your PC.

alank2 02-06-2013 05:47 PM

Hi,

I'm trying to use:

Code:

<!--#include virtual="hello.htm" -->
With hello.html containing:

Code:

<p>hello</p>
But I don't see it including it. I've tried various paths as well...

I've also tried installing iis7 and creating a virtual directory to it and browsing via that but it also does not work.

Any ideas?

Thanks,

Alan

SB65 02-06-2013 06:05 PM

Are you running this on xampp? It requires the file that contains the #include to have the .shtml extension - otherwise it won't work.

felgall 02-06-2013 06:24 PM

web pages that use server side includes need to have a .shtml extension unless you override it in a server configuration file (I'm not sure which file it is for IIS). You also need to be referencing the page via IIS and not directly for the include to work.

alank2 02-06-2013 07:35 PM

Hi,

I'm trying it with the webserver built into win7, iis7.

Is there no easy way to import another html that doesn't have so many requirements?

Thanks,

Alan

felgall 02-07-2013 01:47 AM

There is no way to include files without some sort of server side processing which mreans running a server in order for it to work.

Most web sites end up needing other server side processing in addition to includes and so a server side language such as PHP which supports both processing on the server and includes is a more flexible option than using SSI.

The simplest way to set up a server on your own computer including both a server side language and a database (for storing data on the server after processing) is to download and install XAMPP - http://www.apachefriends.org/en/xampp.html

The best alternative is to set up with a server/language/database combination that is at least similar to what you have on your live web hosting - even if the versions of each are not completely identical (although it is better if they are as then you know what works on your computer will still work when you upload it).

tempz 02-07-2013 01:54 AM

Best method using what the other users have posted above mine.

You can use a iframe but they are very old and kind of useless when it comes to including main features of a website.

Best way to go is with PHP or Javascript.

alank2 02-08-2013 02:46 PM

Hi,

Thanks for all the help everyone, I'll check out xampp.

Alan

alank2 02-13-2013 07:08 PM

Hi,

I got it working with xampp - what other differences are there between file extensions? Should I use .shtml for every page or just ones with includes in them?

Thanks,

Alan

VIPStephan 02-13-2013 08:00 PM

Quote:

Originally Posted by alank2 (Post 1313143)
Should I use .shtml for every page or just ones with includes in them?

That’s entirely up to you. You can also have SHTML files with plain HTML in them (i. e. without includes), or keep the .htm/.html extension but if you have includes they have to be named .shtml (unless you change that in the server config, e. g. through an .htaccess file).

felgall 02-13-2013 08:40 PM

Quote:

Originally Posted by alank2 (Post 1313143)
Should I use .shtml for every page or just ones with includes in them?

There are advantages and disadvantages to both ways.

If you use that extension for all your pages then the pages that don't have includes will load slightly slower because the server has to check if they have includes in them before sending them to the browser.

The advantage that might offset this is that it allows you to add includes into a page that doesn't yet have them without having to rename the file.

StevenHu 02-18-2013 10:03 PM

I wrote an article that included a simple way to incorporate a simple footer using Javascript and innerHTML. See if it will be sufficient in your case:

http://iphonedevlog.wordpress.com/20...gn-techniques/

Look at the "Footer content" section for full working code.

Unfortunately, it isn't good for already existing entire HTML pages.


All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.