It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming HTML Forum

Pulling HTML from external file?

Pulling HTML from external file?

Postby generalchaos316 on Fri Mar 16, 2007 6:22 am

Hey all,

I am just getting started out in the wonderful world of hand-coded web development and have already run into a semi-wall. I am slapping a Navigation Bar at the top of the website like so many others, but I am putting that HTML code into every single HTML file. The problem sets in when, say, I want to add the another link at a later point in time. For example, maybe I was dumb and forgot to put a "Services" page on my startup business' Nav Bar. I now have to go back and change the code on all of the HTML pages to reflect that change. :(

Here is an example of one of my website template page:

Code: Select all
<html>
   <head>
      <title>MadCap-PDC Entertainment</title>
      <link type="text/css" rel="stylesheet" href="madcap.css" />
   </head>
   <body>
   
   <div id="Navigation">
   <p>
      <a href="index.html">Home</a> -
         <a href="shrump.htm">Artists</a> -
      <a href="bios.htm">Representation</a> -
      <a href="contact.htm">Contact</a>
   </p>
   </div> <!-- Close #navigation -->

   <div id="content">
      <p>Cool stuff goes here!</p>
   </div> <!-- Close #content -->

   </body>
</html>


Yeah, the site will look like utter crap with this code but I am trying to get it functional first, and add style second :)

Now I know this will probably become a moot point when I get back into Flash (Java is also up on the table-o-books-to-pour-over) but there just has to be a simpler way of updating my Nav Bar at present time. Much like you can link out to a CSS file and streamline style changes to a website, could I also do this with HTML code as well?

I apologize if this has already been addressed in another post, but I have no idea what this technique is called and thus clueless on how to search for it :) Thanks!
generalchaos316
100+ Club
 
Posts: 101
Joined: Fri Mar 16, 2007 6:01 am

Postby mwa103 on Fri Mar 16, 2007 2:10 pm

It is possible to do this with a server side script like php using an include statement. I discussed this on another topic recently: http://www.devppl.com/forum/need-help-making-dynamic-content-vt5518.html?highlight=

He was wanting to include a txt file, but the method remains the same for html. All you have to do is move your nav bar into a seperate html file (like nav.html) then include that file in each of your pages (they would all have to be changed to php extension like I mentioned in the other post). Basically you would remove the code for the nav bar from each page and replace it with:
Code: Select all
<?php
include "nav.html";
?>


Hope this helps.
-Mike
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 10:55 pm

Doh!

Postby generalchaos316 on Fri Mar 16, 2007 3:29 pm

I pulled the navigation info from the index file and slapped it in its own nav.html file and then replaced that code with what you mentioned. After uploading it to my hosting company I run into the same issue as the other bloke, the browser wants to download the php file. Is this likely to mean that the hosting company does not provide PHP on the server, or do I have to do something other than simply dumping my page to their FTP servers?
generalchaos316
100+ Club
 
Posts: 101
Joined: Fri Mar 16, 2007 6:01 am

Postby mwa103 on Fri Mar 16, 2007 3:40 pm

Sounds like your host doesn't support php. There are a few free hosting sites out there that support php, but most of them put ads on your pages. If you have a contact address for your current host, you could see if they provide something with php support, or if they are planning to add it. They may provide support for a different server side scripting like asp, but I've never used asp, so I couldn't help you code anything up for that.

Another option you could use is frames: http://www.w3schools.com/html/html_frames.asp
or iframes:
http://www.w3schools.com/tags/tag_iframe.asp.
This adds a layer of complexity to your site though and may be difficult to implement.

-Mike
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 10:55 pm

Postby mwa103 on Fri Mar 16, 2007 3:52 pm

Update:

I did some googling and found this page which talks about different ways to include files in your html.
http://www.boutell.com/newfaq/creating/include.html

-Mike

**Edit**
Renaming the page to page.shtml and inserting
Code: Select all
<!--#include virtual="nav.html" -->
Seems to work for me.
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 10:55 pm

w00t!

Postby generalchaos316 on Sat Mar 17, 2007 3:06 am

Thanks for the update. I am at work right now but can't wait to get home and try it out!
generalchaos316
100+ Club
 
Posts: 101
Joined: Fri Mar 16, 2007 6:01 am


Who is online

Users browsing this forum: No registered users and 4 guests