By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,759 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,759 IT Pros & Developers. It's quick & easy.

multiple instances of a CSS link due to server-side fileinclusion and tools requirements

P: n/a
Folks:

As a follow-up to my recent posts, I want to ask some more general questions
about multiple instances of a CSS link in a page as seen by browsers due to
server-side file inclusion. Let me set up my question by providing skeleton
code for two files:

Here's a skeleton of "index.php":

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<link href="TheSiteWideStyles.css" rel="stylesheet"
type="text/css">
....
<head>
...
</head>
<body>
....
<?php
if ($a == 1) { require("ContentChunk1.html"); }
elseif ($a == 2) { require("ContentChunk2.html"); }
elseif ($a == 3) { require("ContentChunk3.html"); }
...
else { require("ContentChunkDefault.html"); }
endif;
?>
...
</body>
</html>

Here's a skeleton of all the content chunk files:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<link href="TheSiteWideStyles.css" rel="stylesheet"
type="text/css">
....
<head>
...
</head>
<body>
...
</body>
</html>

In other words, the chunks are just normal HTML files.

I'm showing a naive computation of which content chunk to include, but that
isn't important for my questions.

Question 1: What's the best way of describing this design, in which the
index page determines the basic site appearance, and specific "inner"
content is selected by a computation at load time? (Sorry, I'm self-taught
and working alone, and I don't always get the terminology right.)

Note that linkage to the site-wide CSS file occurs in all files. Why? At
least in the authoring environment I'm using, Dreamweaver CS3, that's the
only way to make the site-wide styles available to all pages. (DW experts
will realize there's a "weasel clause" to this; I'll get to that in a
moment.)

Question 2: Do other authoring environments handle this differently,
perhaps more cleverly?

Please: I've heard "Don't use DreamWeaver!" too many times already, so
there is no need to repeat it.

Wen index.php is loaded, one of the chunks will be included and client will
see two, (repeat, 2) identical css link tags. When I test the page,
validator.w3.org flags this as an error. Well, no sense in confusing
browsers by sending them invalid code -- some are already confused enough as
it is, right?

Question 3: I think designs based on such an include scheme are very
common. In general, how is this issue avoided -- or, do those page simply
fail the validation test -- or do people not use external css as much as
they should?

DW actually provides a workaround for this issue, a mechanism called
"Design-Time Style Sheets". You can externally mark a specific css link in
a particular file as being valid only at design time. As a result, that
tag is filtered out before the file is uploaded to the server. If I use
that feature and if I eliminate all the header and trailer material in my
content chunks, leaving only stuff that's inside <html>... </html>, all my
pages pass w3c validation. (Woo-Hoo!) But I'm concerned that this
mechanism is a bit fragile in practice.

Question 4: Am I missing something completely obvious that would achieve
the same result without all this trouble? Again, I'm self-taught and I
could be completely oblivious to better ways to do this.

Question 5: Is there a better place to post this question?

TIA,

Henry

remove 'zzz'

Nov 18 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
henry wrote:
<example html snipped>
In other words, the chunks are just normal HTML files.
They shouldn't be. The chunks should be constructed so that the result
after including one inside the other is a normal html file.
Question 2: Do other authoring environments handle this differently,
perhaps more cleverly?
Most of the regulars here use a text editor to write HTML. Yes, a text
editor handles this differently.
Please: I've heard "Don't use DreamWeaver!" too many times already,
so there is no need to repeat it.
If you are going to ask a question, you need to be willing to accept a
correct answer.
Wen index.php is loaded, one of the chunks will be included and
client will see two, (repeat, 2) identical css link tags. When I test
the page, validator.w3.org flags this as an error. Well, no sense in
confusing browsers by sending them invalid code -- some are already
confused enough as it is, right?
Right. Unfortunately, your method is designed to send invalid HTML to
the browser. You have asked us not to tell you how to solve that problem.

Question 3: I think designs based on such an include scheme are very
common. In general, how is this issue avoided -- or, do those page
simply fail the validation test -- or do people not use external css
as much as they should?
The problem is avoided by designing the chunks that make up the
resulting HTML in such a way as to create a valid HTML file after they
are joined together.
DW actually provides a workaround for this issue, a mechanism called
"Design-Time Style Sheets".
<snip>
But I'm concerned that this mechanism is a bit fragile in practice.
I don't know about fragile, but it may be a way to use DW and still get
the results you want.
Question 4: Am I missing something completely obvious that would
achieve the same result without all this trouble? Again, I'm
self-taught and I could be completely oblivious to better ways to do
this.
Learn HTML well enough to write it by hand in a text editor. You may be
using the wrong tool for the job. You can't include a complete HTML file
inside another complete HTML file and expect the result to be a valid
HTML file.

Your content chunk should be just that, a content chunk, not a complete
HTML file.
Nov 18 '08 #2

P: n/a

henry wrote:
>
Question 5: Is there a better place to post this question?
Since your issues seem to be focused around Dreamweaver-specific functions and features, why don't you try a DW forum? They do have their own newsgroups.

--
Berg
Nov 18 '08 #3

P: n/a
henry wrote:
Folks:

As a follow-up to my recent posts, I want to ask some more general questions
about multiple instances of a CSS link in a page as seen by browsers due to
server-side file inclusion. Let me set up my question by providing skeleton
code for two files:

Here's a skeleton of "index.php":

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<link href="TheSiteWideStyles.css" rel="stylesheet"
type="text/css">
....
<head>
...
</head>
<body>
....
<?php
if ($a == 1) { require("ContentChunk1.html"); }
elseif ($a == 2) { require("ContentChunk2.html"); }
elseif ($a == 3) { require("ContentChunk3.html"); }
...
else { require("ContentChunkDefault.html"); }
endif;
?>
...
</body>
</html>

Here's a skeleton of all the content chunk files:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<link href="TheSiteWideStyles.css" rel="stylesheet"
type="text/css">
....
<head>
...
</head>
<body>
...
</body>
</html>

In other words, the chunks are just normal HTML files.

I'm showing a naive computation of which content chunk to include, but that
isn't important for my questions.

Question 1: What's the best way of describing this design, in which the
index page determines the basic site appearance, and specific "inner"
content is selected by a computation at load time? (Sorry, I'm self-taught
and working alone, and I don't always get the terminology right.)

Note that linkage to the site-wide CSS file occurs in all files. Why? At
least in the authoring environment I'm using, Dreamweaver CS3, that's the
only way to make the site-wide styles available to all pages. (DW experts
will realize there's a "weasel clause" to this; I'll get to that in a
moment.)

Question 2: Do other authoring environments handle this differently,
perhaps more cleverly?

Please: I've heard "Don't use DreamWeaver!" too many times already, so
there is no need to repeat it.

Wen index.php is loaded, one of the chunks will be included and client will
see two, (repeat, 2) identical css link tags. When I test the page,
validator.w3.org flags this as an error. Well, no sense in confusing
browsers by sending them invalid code -- some are already confused enough as
it is, right?

Question 3: I think designs based on such an include scheme are very
common. In general, how is this issue avoided -- or, do those page simply
fail the validation test -- or do people not use external css as much as
they should?

DW actually provides a workaround for this issue, a mechanism called
"Design-Time Style Sheets". You can externally mark a specific css link in
a particular file as being valid only at design time. As a result, that
tag is filtered out before the file is uploaded to the server. If I use
that feature and if I eliminate all the header and trailer material in my
content chunks, leaving only stuff that's inside <html>... </html>, all my
pages pass w3c validation. (Woo-Hoo!) But I'm concerned that this
mechanism is a bit fragile in practice.

Question 4: Am I missing something completely obvious that would achieve
the same result without all this trouble? Again, I'm self-taught and I
could be completely oblivious to better ways to do this.

Question 5: Is there a better place to post this question?

TIA,

Henry

remove 'zzz'
The upshot is that the inserts must not have <headerstuff, CSS links,
or even <BODYtags... it must be just the inserted code. You do not
need to validate each insert, only validate the generated code.

I had a similar issue lately when I was working on a Wordpress site. I
don't (yet) use DW, but I read somewhere recently that there's a setting
in DW which allows you to categorise files as inserts, not full docs.
Nov 20 '08 #4

P: n/a
pecan wrote:
The upshot is that the inserts must not have <headerstuff, CSS links,
or even <BODYtags... it must be just the inserted code. You do not
need to validate each insert, only validate the generated code.
Exactly what he has been told in his other post!

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Nov 20 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.