Webforumz's RSS FeedRSS Webforumz RegistrationRegister Contact Webforumz StaffContact

Making duplicate code generic

This is a discussion on "Making duplicate code generic" within the Web Page Design section. This forum, and the thread "Making duplicate code generic are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 14th, 2006, 07:39
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Making duplicate code generic

Hi,

I have the following code in 3 diffreent HTML pages:

<select name="select1" size="1" style="background-color:#FFFFD7">
<option value="./a.htm" target="mainFrame">A</option>
<option value="./b.htm" target="mainFrame">B</option>

What im wondering is that is it possible to modularise this in some way like the way javascript can be added to a .js file. Save me duplicating this code 3 times.

I just want a central place for all duplicated code in forms to save me having to change each occurance.

I been told to use Snippets, but doesnt this just make it easier to copy and paste in between pages?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old Jul 14th, 2006, 11:02
minute44's Avatar
Most Reputable Member

SuperMember
Join Date: Apr 2006
Location: Nottingham UK
Age: 25
Posts: 1,361
Blog Entries: 3
Thanks: 0
Thanked 1 Time in 1 Post
Re: Making duplicate code generic

Quote:
Originally Posted by Rudie View Post
Hi,

I have the following code in 3 diffreent HTML pages:

<select name="select1" size="1" style="background-color:#FFFFD7">
<option value="./a.htm" target="mainFrame">A</option>
<option value="./b.htm" target="mainFrame">B</option>

What im wondering is that is it possible to modularise this in some way like the way javascript can be added to a .js file. Save me duplicating this code 3 times.

I just want a central place for all duplicated code in forms to save me having to change each occurance.

I been told to use Snippets, but doesnt this just make it easier to copy and paste in between pages?

Thanks.
If you're using Dreamweaver or some other WYSIWYG editor then chances are you'll be able to use the library function. this allows you to save imagesm text and code snippets as library items so you can insert them whenever. Kind of like an advanced clipboard.

Hope this helps...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 14th, 2006, 11:48
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Yes, Im using Dreamweaver 8. I'll give that a try when i get home.
I know I can re-use javascript code from the .js files but because this is just HTML, didnt want to code the same piece of code 10 times.

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 14th, 2006, 11:51
minute44's Avatar
Most Reputable Member

SuperMember
Join Date: Apr 2006
Location: Nottingham UK
Age: 25
Posts: 1,361
Blog Entries: 3
Thanks: 0
Thanked 1 Time in 1 Post
Re: Making duplicate code generic

Quote:
Originally Posted by Rudie View Post
Yes, Im using Dreamweaver 8. I'll give that a try when i get home.
I know I can re-use javascript code from the .js files but because this is just HTML, didnt want to code the same piece of code 10 times.

Thanks.
yep, you'll definately be able to do it... you can save anything as a library item in DW. I've done a huge intranet for the place where I work and library items have saved my skin more than once on that project.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 14th, 2006, 17:21
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Hi,

Ive highlighted the code I want to make generic but I cant get the button to add the code into the library enabled. Even the option Modify, Library, Add Object To Library is disabled...

How can I enable?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 14th, 2006, 17:32
Rob's Avatar
Rob Rob is offline
Webforumz Founder

SuperMember
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 28
Thanked 22 Times in 19 Posts
Re: Making duplicate code generic

Maybe you should consider SSI

This can be done in ASP, PHP, JSP, and any other dynamic scripting language.

It can also be achieved using the .shtml extension should you host support SSI.
__________________
Rob - Webforumz Founder

I am currently NOT available for SEO consultancy work

My Sites: Student Midwife Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jul 14th, 2006, 17:33
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Ok, so cant I use this using normal HTML?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jul 14th, 2006, 17:36
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Sorted, I had to add a Site.

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jul 14th, 2006, 20:15
Highly Reputable Member
Join Date: Aug 2005
Location: 3rd Branch Up, Old Oak.
Age: 48
Posts: 658
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

I'm just starting to experiment with CSS and I'm just wondering if you could add the code to an external style sheet and just link any pages to it which require this code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Jul 14th, 2006, 20:20
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Not sure, but I dont like the idea of libraries as its still duplicating code even though a change to the library will update the code used elsewhere.

Surely theres a way to avoid this?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Jul 14th, 2006, 20:22
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Your on the wrong wave length than the comments here Rudie.

Your talking about how to do it in Dreamweaver, whereas the rest of the comments have been about hard coding.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Jul 14th, 2006, 20:27
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Sorry, Eastenders is putting me off ;-)

I basically want to put common code into a seperate place or file and then call it from the web pages where i want to place it, mainly a drop down list.

Hope I make sense.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Jul 14th, 2006, 21:01
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

I think the point has been missed a few times here.

You put the generic code into a file, e.g., 'generic.inc' which you load on the server alomg with your other html files.

Now, as Rob indicated previously, you use one of the scripting methods to 'include' this file at the appropriate place(s) in your html files.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Jul 14th, 2006, 21:05
Junior Member
Join Date: Jun 2006
Location: England
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

Oh ok, is there an example call somewhere?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Jul 14th, 2006, 22:35
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making duplicate code generic

PHP example.

...
...
html code
...

<?php
include ('generic.inc');
?>


...
more html code
...

As Rob stated, if you don;t have access to php but you can use SSI (Server Side Includes), then name your file 'generic.shtml' and use:

<!--#include file='generic.shtml'-->
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati