Saturday 24 September 2011

How can i obtain code/content from an external source page and place in multiple HTML pages?

Hi,



I'm coding a website that i have just designed for somebody. I have the majority of the layout (CSS driven) up and running. I'm using a main content area covering about 2/3 of the width of the page, with the remaining 1/4 being used to hold a floating div, containing %26quot;recent information%26quot; boxes.



I have the positioning on, and the settings for the four small boxes all done. I just need to add content to them. However, I am planning to have these boxes on more than one page, four to be exact.



Is there a way in which i can edit 1 page within the site itself (index.htm), and the changes that i make to the boxes will update all of the same boxes throughout the site (on the other three pages)?



I was wondering whether an external stylesheet of some type could be used, and have code within the box div to refer to that stylesheet. I tried looking into it but came up with no real help...



Note - The content which i want to be placed in each of the boxes is to be placed in a small table.



Much appreciated if you can help me!!



Thanks,

EllisHow can i obtain code/content from an external source page and place in multiple HTML pages?PHP include is the answer... search php include in google.



make sure you rename your .html to .php
How can i obtain code/content from an external source page and place in multiple HTML pages?
I am quite experienced in doing this, one word: AJAX.
How can i obtain code/content from an external source page and place in multiple HTML pages?
What brisray said is accurate. PHP is, by far, the most supported and easiest way to do this. Most likely, you'll be able to include a separate file on each page:



%26lt;html%26gt;

%26lt;head%26gt;...%26lt;/head%26gt;

%26lt;body%26gt;

%26lt;div id=%26quot;sidebar%26quot;%26gt;

%26lt;?php

include('something.php');

?%26gt;

%26lt;/div%26gt;

[The rest of your HTML here]

%26lt;/body%26gt;

%26lt;/html%26gt;



Don't forget to rename your file extensions to .php, or else it won't work.
CSS is used for styling and isn't much use for adding content. What you want to do is possible but how you do it depends on what your server supports. You can use...



ASP then use %26lt;!--#include file=%26quot;file_name.ext%26quot;--%26gt;



PHP then use %26lt;?php include(%26quot;file_name.ext%26quot;); ?%26gt;



If your server cannot support these languages then for AJAX techniques see http://www.xul.fr/en-xml-ajax.html



If you've no server interaction at all you may have to write the included HTML as part of a single JavaScript file and simply use that.