blog.Resource

Archive:

News-Feeds:


RSS 2.0
RSS 0.91
RDF
ATOM 0.3
August 1, 2007

Getting Rid of the XML Prologue

Category: Ron Hall

Sometime back I learned to set my doc type in TYPO3 by using TypoScript code like this:

   config.doctype = xhtml_trans


This tells TYPO3 how to render content and what to set in the final HTML for the Document Type Declaration.

However, I had to stop using that method because it would insert an xml declaration (prologue) in front of the doctype. The prologue looks like this:

   <?xml version="1.0" encoding="iso-8859-1"?>


Technically, it is correct to include this line. However, if it is included, Internet Explorer 6 will render in quirks mode instead of standards mode. Because of this and since other browsers do not require it, it is common practice to leave out this prologue. Since this is what I wanted to do, I had to abandon the method I mentioned earlier and started using the following code to set my doc type:

config.doctype (
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
)


It is too bad that when learning about “doctype” I had not read the TSref a little further for the answer to my situation was just a little lower on the page in the property “xmlprologue.” This is the code I now use:

config {
doctype = xhtml_trans
xmlprologue = none
}


Basically, the following code will tell TYPO3 to render XHTML and provide a Document Type Declaration of XHTML Transitional without including an xml prologue. It also adds the correct xml namespace attribute to the HTML tag.

The doctypeSwitch, xhtml_cleaning and htmlTag_setParams properties (detailed in TSRef) can be of use as well (but I will let you look them up yourself to see if they are something you might want to use).


comments

comment #1
Gravatar: Søren Andersen Søren Andersen August 11, 2007 13:27
You don't have to get rid of the prologue, IE6 only does the quirks mode, when the prologue comes before the DOCTYPE.

Since including the prologue is best practise, of course some developers of TYPO3 have handled this. Do the following in your template:

config {
doctype = xhtml_trans
xhtml_cleaning = all
htmlTag_setParams = xmlns="http://www.w3.org/1999/xhtml" xml:lang="da"
}

[browser = msie] && [version=

comment #2
Gravatar: Søren Andersen Søren Andersen August 13, 2007 16:29
The most important part was missing from my first post:
[browser = msie] && [version=

comment #3
Gravatar: Ron Hall Ron Hall August 28, 2007 03:11
I think your post is still missing something. However, the doctypeSwitch property will also move the prologue to after the doctype.

comment #4
Gravatar: Søren Andersen Søren Andersen September 1, 2007 11:47
Yep Ron that was what my reply was, to use the doctypeSwitch but only on IE versions less than 7. Strangely it seemed like it worked, but then it didn't. I'll past it again, and substitute the "less than" char with (LESS)

config {
doctype = xhtml_trans
xhtml_cleaning = all
htmlTag_setParams = xmlns="http://www.w3.org/1999/xhtml" xml:lang="da"
}

[browser = msie] && [version= (LESS)7]
config.doctypeSwitch = 1
[global]

With this typoscript, you'll keep the prologue as you should, and place it correctly with regards to the standards, unless the visitor has IE less than 7, which will result in a switch, that prior versions of IE has to have.

Sorry, comments are closed for this post.