The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> HTML Duplicate Code / HTML Code Re-use
Brad364
post Sep 28 2007, 03:37 PM
Post #1





Group: Members
Posts: 4
Joined: 6-September 07
Member No.: 3,735



I want to develop a web site with several dozen pages. Being new at this I wonder on how to minimize redundant code across all these pages.

What I seem to see is that the HTML code content from the DOCTYPE declaration on through to the <body> opening clause would generally be identical to all these pages, so that if I ever want to change this portion of the site, I'd have dozens of places to maintain the code. Specifically, the <head> - </head> portion of each page would seem to be identical. (I assuming it would be at least).

So, how do others minimize this redundant specification of this segment of code on dozens of pages? SSI? Some kind of code editor?

Thanx in advance.

Brad
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Sep 28 2007, 03:41 PM
Post #2


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



Please see the FAQ entry How do I include one file in another?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Sep 29 2007, 03:32 AM
Post #3


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



Would one really do that for the HEAD section of a page?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 29 2007, 06:53 AM
Post #4


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(Frederiek @ Sep 29 2007, 10:32 AM) *

Would one really do that for the HEAD section of a page?

I once did. Couldn't make up my mind about which Doctype and CSS loading code to use, so I made a function that printed it all, with the TITLE text as the function argument. I've removed it now. blush.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 29 2007, 10:10 PM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



QUOTE(Frederiek @ Sep 29 2007, 10:32 AM) *

Would one really do that for the HEAD section of a page?


Why not? You mean if one later wants to add a snip of page specific CSS or something? I would leave head open, i.e. not include the closing head tag.

CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Christian's Knitwear</title>
# INCLUDED STUFF #
</head>
<body>
<p></p>
</body>
</html>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Sep 30 2007, 03:40 AM
Post #6


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



I can imagine using it for repeated snippits in the BODY, but the HEAD...
Oh well, it's not that if I've never seen or heard of it, that it doesn't exist or hasn't been done before.
I just wondered.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brad364
post Sep 30 2007, 02:47 PM
Post #7





Group: Members
Posts: 4
Joined: 6-September 07
Member No.: 3,735



All of these answers were good for me. It helps me learn....especially about NOT using such a technique in the <HEAD> portion.

Specifically, what I am getting at is, the fact that just a single specification on every web page (where there are dozens of pages) to the same STYLESHEET spec, or BASE spec or any thing redundantly coded again and again seems like such a maintenance burden.

I found another method of avoiding redundant specification. See http://mindprod.com/jgloss/htmlstaticmacros.html

Here, he uses an off-line utility to paste together specs that compose each page. If say something like the CSS spec, or DOCTYPE spec changes, he changes it once, and re-generates all pages via automation. This technique also would be helpful, if say a certain spec was needed to be added anew to all pages.

Thanx to all for their replies.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 30 2007, 04:45 PM
Post #8


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



I still don't see why includes shouldn't be used for sections of HEAD. As you say, it can be messy there.
I see now my HTML example above was stupid. Unless you do what Christian did, the TITLE can't be inluded. I'll change it so no one gets bad ideas from it. blush.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
non-profit
post Oct 9 2007, 10:45 PM
Post #9


Member
***

Group: Members
Posts: 45
Joined: 25-March 07
Member No.: 2,321



QUOTE(Brad364 @ Sep 28 2007, 01:37 PM) *

I want to develop a web site with several dozen pages. Being new at this I wonder on how to minimize redundant code across all these pages.

What I seem to see is that the HTML code content from the DOCTYPE declaration on through to the <body> opening clause would generally be identical to all these pages, so that if I ever want to change this portion of the site, I'd have dozens of places to maintain the code. Specifically, the <head> - </head> portion of each page would seem to be identical. (I assuming it would be at least).

So, how do others minimize this redundant specification of this segment of code on dozens of pages? SSI? Some kind of code editor?

Thanx in advance.

Brad


Klutzy as it is, I use http://www.funduc.com/srshareware.htm. This mechanical way of altering identical code means that you have to re-upload all of your pages. If you had hundreds of pages, it seems to me that it would be worth getting sophisticated. For "dozens of pages," this solution has worked for me. K[eep]I[t]S[imple].
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Oct 10 2007, 03:16 AM
Post #10


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



The HTML preprocessor I use allows me to define a "header" and a "footer". The "header" includes everything I want to appear before the main content, which includes the doctype declaration, the head element, the <body> tag, breadcrumb links, the h1 element, etc. The "footer" includes everything I want to appear after the main content, which includes the copyright info at the bottom, when the document was updated, the </body> tag, etc.

Several content management systems that I've used control everything except the main content that I'm allowed to edit.

I don't see what's so special about the head element that it shouldn't be generated automatically.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th April 2024 - 06:18 AM