Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy Forums > > >

Including a file in another html file.


(!)

Jojoejoe3's Avatar
Member with 1 posts.
THREAD STARTER
 
Join Date: Jul 2012
11-Jul-2012, 09:00 PM #1
Including a file in another html file.
I have a sidebar that's used across my website and I decided that I need to update it every now and then but I don't want to update 50+ pages to just add or remove a few words. So I googled around a bit, and I found that I could just include it. But my sidebar is being put on the page via css I was wondering what the sidebar.htm page needed to have so here is the current sidebar code:
HTML Code:
<div class="sidebar_container">   		  
		  <div class="sidebar">
            <div class="sidebar_item">
                <h2>Community Service</h2>
			    <h4>July 9th-12th 2012</h4>
                <p>Meet at the school to help move things from the old building to the new one!</p>
		          <a href="#">Read more</a>
              </div><!--close sidebar_item--> 
          </div><!--close sidebar-->     		
		 <div class="sidebar">
            <div class="sidebar_item">
              <h2>Community Service</h2>
		  	  <h4>TBA</h4>
              <p>None at the moment.</p>
		        <a href="#">Read more</a>
            </div><!--close sidebar_item--> 
          </div><!--close sidebar-->  
		  <div class="sidebar">
            <div class="sidebar_item">
          <a href="*****"><h2>Facebook Page</h2></a>
            </div><!--close sidebar_item--> 
            </div><!--close sidebar-->  
           </div><!--close sidebar_container-->
What should I put in the sidebar.htm and where do I put the <!--#include file="sidebar.htm" --> on my other pages so when I update the sidebar it updates it on every page?
colinsp's Avatar
Computer Specs
Member with 1,391 posts.
 
Join Date: Sep 2007
Location: Spain
12-Jul-2012, 01:27 AM #2
The easiest way is to do this with php if your server supports it.

Rename your base page with the php extension and your sidebar also with php as the extension

Where you want the sidebar in your main page put

Code:
<?php 
 include 'sidebar.php';
 ?>
Your sidebar code above (if it works now) needs no additional code in it just the change in file extension.
allnodcoms's Avatar
allnodcoms   (Danny) allnodcoms is offline allnodcoms has a Profile Picture
Computer Specs
Member with 601 posts.
 
Join Date: Jun 2007
Location: Hertfordshire - England
Experience: Advanced
12-Jul-2012, 01:44 AM #3
Hi, and welcome to the boards...

There is no 'include' tag in HTML, per se. There is a server side include (which works as you described) but you need the appropriate backend, i.e. Apache, to make this happen.

The easiest way to get this on your pages, and by far the most common, is to use an iframe on each page that you want to contain your sidebar. The iframe tag has a source (src=) attribute that you would set to sidebar.htm.

An iframe is like a window in your page, through which you can see another. The source page takes nothing from the parent window so you would need to embed your CSS sheets in the sidebar. It also has to be a valid page, so you will need the <html> tags down to make it work.

Danny
__________________
"An Apple a day keeps the Gatesy at bay"
colinsp's Avatar
Computer Specs
Member with 1,391 posts.
 
Join Date: Sep 2007
Location: Spain
12-Jul-2012, 03:52 AM #4
Danny, ifames are supposed to be deprecated but if server includes don't work for whatever reason then I suppose needs must.
allnodcoms's Avatar
allnodcoms   (Danny) allnodcoms is offline allnodcoms has a Profile Picture
Computer Specs
Member with 601 posts.
 
Join Date: Jun 2007
Location: Hertfordshire - England
Experience: Advanced
12-Jul-2012, 04:08 AM #5
Colin, it's frame sets that are deprecated, and have been for some time. iframe is part of the proposed HTML5 spec and was introduced to replace the older frame set model. Without SSI, the iframe is the only way (short of setting 'innerHTML' through AJAX) that you can 'include' one HTML document within another...

Danny
__________________
"An Apple a day keeps the Gatesy at bay"
colinsp's Avatar
Computer Specs
Member with 1,391 posts.
 
Join Date: Sep 2007
Location: Spain
12-Jul-2012, 04:30 AM #6
Danny, thanks learn something new every day
allnodcoms's Avatar
allnodcoms   (Danny) allnodcoms is offline allnodcoms has a Profile Picture
Computer Specs
Member with 601 posts.
 
Join Date: Jun 2007
Location: Hertfordshire - England
Experience: Advanced
12-Jul-2012, 04:44 AM #7
No worries... Anytime

Danny
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑