[web] Website Design: Repeating Sidebars

Started by
10 comments, last by Geometrian 15 years, 12 months ago
Hi, -This is my website: http://www.geometrian.com/Programs.html -As you can see, there is a title and a top and side bar. -Note that Projects.html and Message%20Board.html have precisely the same setup, and every one of my projects is accessible from any page. -Every time I release a new project or a new update, I must update these three pages' sidebars. I must change the links to the file on the sidebar. This is annoying. -As if this weren't bad enough, I want to add more pages, but I'm not willing to update five or six pages every time I change one thing. -I've heard of a way to change one file and have it change many pages that are based on it. I've heard that this is faster, too, as it must only load the sidebar once. This is precisely what I need. -Could someone please show me what to do with this website, or create a simple example site that shows how to deal with this problem? Thanks, Geometrian

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
If you are developing this site in straight HTML, Dreamweaver (among others) allows you to define the navigation bar as a 'library item', and include it in each page. If your server supports Server Side Includes, you can use those to add the menu bar. You can also achieve the same result using php/asp/jsp.

However, I would very much suggest that you transition to a Content Management System (CMS) instead. Modx is quite nice, although for a site this small you might consider abusing WordPress instead.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

You don't need a CMS at all. Change all your main files into .php extensions. Then, take everything in your <div class="nav"> and put it in a file called sidebar.html. Now go back to your php files and add this instead of the entire sidebar:

<div class="nav">  <?php include_once(sidebar.html); ?></div>


Tada :D

Edit: fixed source :S

[Edited by - Karan Bhangui on April 21, 2008 10:05:59 PM]
Quote:(heck, Python is based on C++).

Uh, no.
Quote:Original post by Karan Bhangui
You don't need a CMS at all. Change all your main files into .php extensions. Then, take everything in your <div class="nav"> and put it in a file called sidebar.html. Now go back to your php files and add this instead of the entire sidebar:
So, basically, take all the sidebar code, then put it into a separate file, then call it from every other file?
Quote:Original post by Oluseyi
Quote:(heck, Python is based on C++).
Uh, no.
I see that. Apparently I was misinformed. I'll rectify that situation when I get home. Thanks for catching that...

Ian

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Yes, essentially you want to isolate what is static from what is dynamic. Put your navigation into its own file and include it on every page using any of the aforementioned mechanisms.

To do it with SSI (Server-side includes) you can do something like this:

<!--#include virtual="/path/relative/to/the/web-server/root/navigation.html" -->


Or like this:

<!--#include file="path/relative/to/the/file/navigation.html" -->


Info about file and virtual.

As a good practice you should use a .shtml extension if your file has SSI processing instructions. Most of the time, though, servers are set up to parse files with .html and .htm extensions too. There's a small performance hit for doing it this way (since .html and .htm files will be parsed for SSI instructions whether they have any or not) but I wouldn't worry about it.
Neither of these worked.

In the case of the former, I think it is because my server doesn't use php. How can I install it?

In the case of the latter, Dreamweaver CS3 (what I use) seemed to recognise it, but opening the file in Firefox didn't get the right effect. It said "Server Side"--does that mean it has to be FTP-ed first?
Edit: FTP-ing my test site didn't seem to help...

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

You're correct in your first assumption -- including files with SSI is indeed processed by the server. Opening them locally will not do the trick (DW will emulate this effect, though).

One way to tell if your server has SSI turned on is to view the source after you've FTP'd it to the server. If the include processing instructions are still there then the server is not processing them.

The effects with PHP will be the same.
How do I activate SSI or PHP then?

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

It is more likely than not that you have PHP enabled on the server. Just upload a php file with something like:
<?php echo 'test'; ?>
to test if you do. If it prints test, then its installed. No further 'activation' is required.

And I highly suggest the php option, the rest are a bit nonstandard/outdated.

(Edit: Fixed php source in previous post. I forgot to add the <?php and ?> tags which tell apache to activate php parsing, which is probably why it didn't work.)

This topic is closed to new replies.

Advertisement