Forum Moderators: open

Message Too Old, No Replies

Loading a HTML snippet into my page

How do I do it?

         

hexdj

6:14 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



I am fairly new in the HTML programming world and I am wondering if it's possible to load a unordered list into my page (i.e. an UL that becomes a a navigation menu) into every page, I don't want to have to change every file's HTML in case the menu changes.

For Example let's say this is my navigation menu contained in a file (let's say ulmenu.html)

<ul>
<li>home </li>
<li>info </li>
<li>contact </li>
</ul>

And my page (any page in my website) looks like this:

...
<body>

<div id="navMenu">

here's where I'd like to insert my external HTML!

</div>
...

I would like to know if this is possible to save myself a lot of work... Thanks.

jbinbpt

6:17 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi hexdj,
I believe you are looking for includes.

Check out this post...
[webmasterworld.com...]

jb

hexdj

6:18 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



Wow, that was fast! thanks a lot! ;)

hexdj

6:21 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



is there anyway of doing it without PHP though? I am not sure the server I will be using supports PHP.

encyclo

6:25 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the forums, hexdj.

If you don't have PHP, then you can do something very similar with ASP (available on most Windows-based servers) or SSI (Server-Side Includes). What kind of server-side language will be available to you?

hexdj

6:39 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



actually my server does support PHP, I am with earthlink and in my control panel it says they support 2.x and 3, doesn't say anything about newer versions though, would that be a problem for me?

encyclo

6:42 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Best way is to create a text file (with Notepad) and save it as test.php with the following contents:

<?php phpinfo();?>

Upload it to your hosting space and call up the file in your browser. The page should print the PHP version number and a whole load of other information. Otherwise, if in doubt, just contact your host.

hexdj

6:50 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



do I need to have anything else in that file? like doctype or can it be just plain like that? I just tried it and my browsers just give me the option to open or save it, either way does not show anything in it.

maybe I need to have my php activated in my server or something?

jbinbpt

6:59 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this.... save as test.php and upload


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php phpinfo();?>
</body>
</html>

hexdj

7:09 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



IE shows nothing and Firefox only shows whatever HTML code is in the test.php file.

encyclo

9:02 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds as if PHP isn't enabled, hexdj. You should email your host to get instructions. :)

hexdj

10:08 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



Earthlink said they have no support for php on my account.

Is it possible to do this with CGI?

BlobFisk

10:11 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do this at the client side using Javascript and hte xmlHTTPrequet method...

jbinbpt

11:47 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do a search for CGI includes. It will work also.

jb

hexdj

11:36 am on Aug 9, 2005 (gmt 0)

10+ Year Member



Doesn't it work with simply using iFrame and load whatever.html as src?