Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2013, 03:36 PM   PM User | #1
alank2
New Coder

 
Join Date: Jun 2012
Posts: 25
Thanks: 4
Thanked 0 Times in 0 Posts
alank2 is an unknown quantity at this point
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
alank2 is offline   Reply With Quote
Old 02-06-2013, 03:38 PM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
No, server side includes is the best way - have a look at using PHP includes.
__________________
Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
Read Steve Krug's book Don't Make Me Think - essential reading on web usability
I don't recommend much, but I do recommend Clook for UK web hosting
SB65 is offline   Reply With Quote
Old 02-06-2013, 03:56 PM   PM User | #3
alank2
New Coder

 
Join Date: Jun 2012
Posts: 25
Thanks: 4
Thanked 0 Times in 0 Posts
alank2 is an unknown quantity at this point
Hi,

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

Thanks,

Alan
alank2 is offline   Reply With Quote
Old 02-06-2013, 05:22 PM   PM User | #4
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
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.
__________________
Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
Read Steve Krug's book Don't Make Me Think - essential reading on web usability
I don't recommend much, but I do recommend Clook for UK web hosting
SB65 is offline   Reply With Quote
Old 02-06-2013, 05:47 PM   PM User | #5
alank2
New Coder

 
Join Date: Jun 2012
Posts: 25
Thanks: 4
Thanked 0 Times in 0 Posts
alank2 is an unknown quantity at this point
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
alank2 is offline   Reply With Quote
Old 02-06-2013, 06:05 PM   PM User | #6
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
Are you running this on xampp? It requires the file that contains the #include to have the .shtml extension - otherwise it won't work.
__________________
Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
Read Steve Krug's book Don't Make Me Think - essential reading on web usability
I don't recommend much, but I do recommend Clook for UK web hosting
SB65 is offline   Reply With Quote
Old 02-06-2013, 06:24 PM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,453
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 02-06-2013, 07:35 PM   PM User | #8
alank2
New Coder

 
Join Date: Jun 2012
Posts: 25
Thanks: 4
Thanked 0 Times in 0 Posts
alank2 is an unknown quantity at this point
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
alank2 is offline   Reply With Quote
Old 02-07-2013, 01:47 AM   PM User | #9
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,453
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 02-07-2013, 01:54 AM   PM User | #10
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
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.
tempz is offline   Reply With Quote
Old 02-08-2013, 02:46 PM   PM User | #11
alank2
New Coder

 
Join Date: Jun 2012
Posts: 25
Thanks: 4
Thanked 0 Times in 0 Posts
alank2 is an unknown quantity at this point
Hi,

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

Alan
alank2 is offline   Reply With Quote
Old 02-13-2013, 07:08 PM   PM User | #12
alank2
New Coder

 
Join Date: Jun 2012
Posts: 25
Thanks: 4
Thanked 0 Times in 0 Posts
alank2 is an unknown quantity at this point
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
alank2 is offline   Reply With Quote
Old 02-13-2013, 08:00 PM   PM User | #13
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,602
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Quote:
Originally Posted by alank2 View Post
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).
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 02-13-2013, 08:40 PM   PM User | #14
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,453
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by alank2 View Post
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 02-18-2013, 10:03 PM   PM User | #15
StevenHu
Regular Coder

 
Join Date: Jun 2011
Location: CA
Posts: 105
Thanks: 0
Thanked 10 Times in 10 Posts
StevenHu is an unknown quantity at this point
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.
__________________
Steve Husting
http://iphonedevlog.wordpress.com

Last edited by StevenHu; 02-20-2013 at 06:09 PM..
StevenHu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:23 PM.


Advertisement
Log in to turn off these ads.