How to embed (almost) any document to HTML?

Using html to design and store parts of webpages separate from each other?

  • I'm trying to design using css/html and I want to store the content of the sidebar outside of the main html, so that if I need to change it later, I don't have to change it in 10,000 documents on my site. I know CSS lets you control the look of the page but is there any similar function for the content? I have tried loading a text/html document into the main html using embed,object,iframe...but nothing works. Can anyone help?

  • Answer:

    I use Server Side Includes for exactly the reason you want to use them. You'll have to set up your .htaccess file and then make the include file(s) that will be edited at times. Using the include code on the pages where you want them will allow you to just edit one include file, upload and overwrite the old one and all changes will take effect on every web page calling that include file. You can use the PHP Include method if you prefer. Using Includes in a webpage: http://www.htmlbasix.com/includes.shtml PHP: http://www.ibdhost.com/help/templates/ Ron

A & D B at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

I'd recommend using PHP to preprocess the file, but you can also use javascript. If using PHP, make a php file that represents the sidebar. put it in the form of a variable. In the main html/php, include the other file and echo the variable where the side bar should go. If using JavaScript, it is basically the same idea. include a javascript file that has a function that you can call that uses document.write. Include the javascript file using <script src="filename"></script> and when you get to the side bar, call the function with a script. Hope this helps!

Macadameane

Please don't use frames like the first person said. Use a PHP include statement, I have these constructing most of my site haha. Here's how to do it: <?php include('/link/to/file.html'); ?> The file that you link to can be named with any extension (ie. html phtml php), just make sure that what it contains is the exact code you want to be shown on the page... so... <body> <h1>Welcome</h1> <?php include('file.html'); ?> </body> file.html could be: <div id="menu"> home | info | log out </div> and that code would be pasted where the include statement is: <body> <h1>Welcome</h1> <div id="menu"> home | info | log out </div> </body> NOTE: YOU NEED TO NAME EVERY PAGE THIS IS BEING USED IN WITH EITHER A .PHP OR .PHTML ENDING OR THIS WILL NOT WORK!!!!!! IT SHOULDN'T EFFECT ANYTHING NEGATIVELY THOUGH.

hola

I don't think you can do that with just HTML. You can do it using JSP, ASP or PHP.

jackkirby

you need to utilize frames. it separates your webpage into sections http://www.w3schools.com/html/html_frames.asp

c0d3pRaDa

Check if your web server supports "server-side includes" ("SSI"). If it does, there's no need to use anything other than straight HTML and CSS. No scripting languages needed. I use this on my website to put the top banner, main menu, and sidebar into their own files. Then, on each page, I simply include this at the top of the "body" section: <!--#include virtual="/inc/banner.inc" --> <!--#include virtual="/inc/mainmenu.inc" --> <!--#include virtual="/inc/sidebar.inc" --> I then have a "inc" directory within my "htdocs" directory (some systems use "public_html" instead), where I place these files. Over the holidays, I had this in my "/inc/banner.inc" file: <div id="Notice"> Please note that our offices will be closed for the holidays from Thursday, 24-Dec-2009 through Sunday, 3-Jan-2010 </div> This notice then "magically" appeared in the banner on every page on my site. In my CSS file, I have this style for my sidebar, to keep it on the left side: #SideBar { background: rgb(162,192,198); color: black; font: 10pt Arial; width: 15em; float: left; /* padding: 5px 10px 5px 0px; */ margin: 0px 2em 0px 0px; } and within "inc/sidebar.inc", I place everything within <div id="SideBar"> to place it properly. - kb -

Ken B

Try a Dreamweaver. It`s easy to understand.

Montenrro !

Agree, don't use frames, they are very 1997

jimbot

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.