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.
|
|
|
|
|
![]() |
||
Making duplicate code generic
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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. |
|
|
|
#2
|
||||
|
||||
|
Re: Making duplicate code generic
Quote:
Hope this helps...
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
Re: Making duplicate code generic
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.
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
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.
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
#7
|
|||
|
|||
|
Re: Making duplicate code generic
Ok, so cant I use this using normal HTML?
|
|
#8
|
|||
|
|||
|
Re: Making duplicate code generic
Sorted, I had to add a Site.
Thanks. |
|
#9
|
|||
|
|||
|
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?
|
|
#10
|
|||
|
|||
|
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. |
|
#11
|
|||
|
|||
|
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. |
|
#12
|
|||
|
|||
|
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. |
|
#13
|
|||
|
|||
|
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. |
|
#14
|
|||
|
|||
|
Re: Making duplicate code generic
Oh ok, is there an example call somewhere?
|
|
#15
|
|||
|
|||
|
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'--> |
|
#16
|
|||
|
|||
|
Re: Making duplicate code generic
Sorry for sounding thick, but if the generic.shtml (i dont know PHP thats why ive chose SSI) includes my drop down list code, how do I bring in the code from the generic.shtml onto my main page?
Is there a way to wrap it into a function or something? |
|
#17
|
|||
|
|||
|
Re: Making duplicate code generic
You just position the include statement at the point in your html where you want the generic code included. The server effectively merges the two files together before sending it to the browser. |
|
#18
|
|||
|
|||
|
Re: Making duplicate code generic
Hi,
Im almost there, ive saved the common code into a .shtml file, called this from within another page, the cut out code shows up in design view, but on execution, it does not show. Can anyone please help? Thanks. |
|
#19
|
|||
|
|||
|
Re: Making duplicate code generic
Let's see both your generic code and the section of code from your main pages(s) that include the generic code. Include the code either side of where you include the generic file. |
|
#20
|