Click to See Complete Forum and Search --> : How can I use common code on multiple web pages?
ddbell
02-14-2010, 07:55 PM
I have about 20 html pages that will all share some common html coding. The common elements will be changed and updated frequently.
Is there an easy way to have 1 document that contains the common code that is used by all 20 pages so I don't need to updated all of the pages each time?
Also, I want to stay away from frames.
Thanks, Damon
nikiitea
02-14-2010, 09:40 PM
try this using php:
save the common code in a temp.php and include it wherever you need in your webpage using the include command
silverline
02-14-2010, 10:10 PM
As I understand ,
The best solution to your problem is using php.
Just separate header,sidebars,mainbody,and footer section in different pages...
and put it in the pages by using include_once or require_once command.
We are using this process in all our projects and it can be implemented easily and successfully..
Best OF LUck
chris22
02-15-2010, 01:24 AM
a historical note:
Long time ago (before PHP and other scripting languages became popular), people used M4 macro processor to include common elements into HTML pages. A nice article describing the process:
http://www.linuxjournal.com/article/2393
ArtphotoasiA
02-15-2010, 10:01 AM
I just posted about here
http://www.webdeveloper.com/forum/showthread.php?p=1068271#post1068271
have a look
ddbell
02-16-2010, 12:27 AM
Thanks for the replies. I'll check out these methods and try them on my website.
savvykms
02-16-2010, 01:48 PM
Try using an external Javascript file. For help on how to do that, check out the Javascript forum here. Basically:
<script src="somefile.js" type="text/javascript" langauge="javascript"></script>
appletree
02-16-2010, 11:09 PM
Nikiitea was right but he didn't explain it. Here's a quick explanation:
Step 1. Rename all your .html pages to .php
Step 2. Open notepad and paste the common html into a document.
Step 3. Save the common html document as your_title.php
Step 4. Open the 20 HTML pages and paste this code in the spot where you want the common code to appear:
<?PHP include("http://yourwebsiteurl.com/your_title.php"); ?>
Now when you make changes to the your_title.php file, it will update all your pages.