PDA

View Full Version : Reducing redundant code?



shewhorn
28 Jan 2010, 11:13 PM
Hi everyone,

First post here. A bit of background first... I used to be a C, C++, and x86 assembly software engineer. I spent a lot of time making sure I was utilizing good object oriented techniques when coding and in the process of learning html I find myself initially frustrated because this seems difficult to do with HTML. As a result the HTML code I'm generating has A LOT of redundancy and A LOT of opportunities to miss something as the site grows if I decide to make a change to the redundant code in question. I assume there actually are some good ways to practice OOP with web design but since I'm so new... I just don't know where to look yet.

Okay that said, how 'bout an example. I need to get up to speed fast so I figured Dreamweaver was a good way to do this. So far so good but I've run into a bit of frustration with the menu bar.

The website I'm designing has a menu bar and that bar is the same under every web page. I'm using the Spry Menus in CS4. So, let's say I have the following menu structure:

home || about || pulldown1 || pulldown2 || contact || location

so home links to index.html, about to about.html, contact to contact.html and location to location.html

pulldown1 and pulldown2 contain links to topical items so they are in a folder on the root (called pulldown1 and pulldown2 respectively). Each submenu has several items... a, b, c, etc. which would be associated with a.html, b.html, c.html, etc. If you select c.html it displays the content for that page... here's the kicker... the UI maintains the SAME nav menu throughout the entire website but in order to do that the code for the menubar must be replicated on EVERY single HTML file and I don't like having redundant code. Should I decide to change that at some point I have to edit EVERY single file on the website.

Ultimately I don't want that. I would like to have the menu bar code in ONE place so if I change it, I just change one file. It would be great to write a menu function of sorts that I could just call from each html file and just have a #include at the top defining each function so as to not have to replicate the same code all over.

Can someone point me in the right direction of how I might go about doing this with html?

Cheers, Joe