Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

xhtml_support - application/xhtml+xml

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
newphase
Smarty Rookie


Joined: 03 Jun 2004
Posts: 9

PostPosted: Fri Jun 04, 2004 12:51 pm    Post subject: xhtml_support - application/xhtml+xml Reply with quote

This was merely for personal use, but a few people have asked me about it so here it is. Allows template to conform to specification and serve pages in application/xhtml+xml when available, text/html when not.

Adapted from a php implementation of this discussion http://www.klio.org/marks/2003_04_archive.html#entry-40

PHP Source File: http://junk.newphase.org.uk/function.xhtml_support.phps

usage example:
Code:
{xhtml_support doctype="4" encoding="iso-8859-1" quirks="true"}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>

etc etc
Back to top
View user's profile Send private message
xces
Smarty Regular


Joined: 09 Apr 2004
Posts: 77

PostPosted: Wed Jun 09, 2004 12:56 pm    Post subject: Reply with quote

Very nice work newphase, i will try this on my CMS tonight for it is completely XHTML 1.0 strict, let's see if it makes an difference in FireFox / IE etc.
Back to top
View user's profile Send private message
sage
Smarty Rookie


Joined: 09 May 2004
Posts: 20
Location: London, UK

PostPosted: Wed Jun 09, 2004 4:40 pm    Post subject: Reply with quote

You could also try André Rabold's DOCTYPE header plugin

(I modified it for doing XHTML 1.1 as well)

http://smarty.incutio.com/?page=DOCTYPEHeaderPlugin
Back to top
View user's profile Send private message
newphase
Smarty Rookie


Joined: 03 Jun 2004
Posts: 9

PostPosted: Wed Jun 09, 2004 4:52 pm    Post subject: Reply with quote

I did read over André Rabold's similar plugin. But it does not offer the same functionality as mine is intended merely for use with XHTML. Also André's doesn't cover the sending of headers as discussed in the article I posted above, meaning that if browsers were to prefer a new mime-type over application/xhtml+xml it would not recognise this.

Not even sure if my implementation is complete yet. Not sure if I should include the <html> tag as well or keep it as an additional option.

Any ideas on making this plugin run slightly smoother appreciated.

newph.

[edit:] is that the best way to test for an internet explorer browser? or can somebody suggest a more fullproof method?[/edit]
Back to top
View user's profile Send private message
sage
Smarty Rookie


Joined: 09 May 2004
Posts: 20
Location: London, UK

PostPosted: Wed Jun 09, 2004 5:16 pm    Post subject: Reply with quote

Thats pretty cool,

Unfortunatly I still need the HTML entries that the DOCTYPE plugin provides as Opera does not handle javascript properly with XHTML (well at least with 7.23), and I had to make a detect for it Sad

It would be nice to merge the 'quality' capability of your plugin with that of André's...
Back to top
View user's profile Send private message
pt2002
Smarty Regular


Joined: 05 May 2003
Posts: 89
Location: Porto, Portugal

PostPosted: Thu Jun 10, 2004 9:48 am    Post subject: Reply with quote

Hi

I was trying to use DOCTYPE plugin. First line of template:

{html_doctype xhtml=true version="1.0" type="strict"}

I get an error with Mozilla Firefox 0.8

"This XML file does not appear to have any style information associated with it. The document tree is shown below."

The browser shows the html source code instead render it. If I add sendheaders=false parameter, it works fine.

Greetings
pt2002
Back to top
View user's profile Send private message
sage
Smarty Rookie


Joined: 09 May 2004
Posts: 20
Location: London, UK

PostPosted: Thu Jun 10, 2004 10:15 am    Post subject: Reply with quote

I use a slightly cut down version of the DOCtype plugin, which is based on version 1.3, with my opera detect in it...

I never tested out André's new HTTP_ACCEPT header checks (as I thought only the application/xhtml+xml was important for xhtml).

The header checks that I use are
[php:1:69d9166193]
if ($xhtml) {
if ($sendheaders) {
// first check if browser accepts application/xhtml+xml content type
if (stristr($_SERVER['HTTP_ACCEPT'],"application/xhtml+xml")) {
header("Content-Type: application/xhtml+xml; charset=$encoding");
}
//Send everyone else text/html
else {
header("Content-Type: text/html; charset=$encoding");
}
}
[/php:1:69d9166193]

This works for me (my site is using XHTML 1.1 and firefox says the type is application/xhtml+xml) but quickly comparing the codes I cant obviously see why the other would not work.
Back to top
View user's profile Send private message
sage
Smarty Rookie


Joined: 09 May 2004
Posts: 20
Location: London, UK

PostPosted: Thu Jun 10, 2004 10:29 am    Post subject: Reply with quote

What is the Doctype that is outputted on your HTML pages (it sounds as if the doctype is wrong)?

The only thing I can see is that the type (Strict) should be with a capital "S", as this is passed directly to the doctype string.

Quote:

{html_doctype version="1.0" type="Strict"}
Back to top
View user's profile Send private message
pt2002
Smarty Regular


Joined: 05 May 2003
Posts: 89
Location: Porto, Portugal

PostPosted: Thu Jun 10, 2004 11:18 am    Post subject: Reply with quote

Hi

Still get the same error and the html source code on the browser after applying your suggestions and code.
Firefox says application/xhtml+xml but only show the page with sendheaders=false

Works fine with Opera 7.5.

Thank you very much anyway

Greetings
pt2002
Back to top
View user's profile Send private message
sage
Smarty Rookie


Joined: 09 May 2004
Posts: 20
Location: London, UK

PostPosted: Thu Jun 10, 2004 11:39 am    Post subject: Reply with quote

Quote:
Still get the same error and the html source code on the browser after applying your suggestions and code.
Firefox says application/xhtml+xml but only show the page with sendheaders=false


Thats very odd...

What are the first lines of text given (the XML declaration and doctype)?
And is the page rendering in quirks mode with firefox when you set headers to false?
Back to top
View user's profile Send private message
pt2002
Smarty Regular


Joined: 05 May 2003
Posts: 89
Location: Porto, Portugal

PostPosted: Thu Jun 10, 2004 2:37 pm    Post subject: Reply with quote

Hi

with sendheaders=false, page source is

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
...
...
...


Without sendheaders in IE
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
...
...

Without sendheaders in Firefox only shows document tree starting with <html> tag

Greetings
pt2002
Back to top
View user's profile Send private message
sage
Smarty Rookie


Joined: 09 May 2004
Posts: 20
Location: London, UK

PostPosted: Thu Jun 10, 2004 4:33 pm    Post subject: Reply with quote

pt2002 wrote:


page source is

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
...
...
...


You are using strict.... if so the <html> element must contain a namespace... That may be the problem (firefox is quite strict about things like that):

Code:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">


p.s. Unless its neccessary you may want to use UTF-8 as the encoding type.
Back to top
View user's profile Send private message
xces
Smarty Regular


Joined: 09 Apr 2004
Posts: 77

PostPosted: Thu Jun 10, 2004 4:49 pm    Post subject: Reply with quote

I would like to know if there where made any improvements since you started this post?
Back to top
View user's profile Send private message
newphase
Smarty Rookie


Joined: 03 Jun 2004
Posts: 9

PostPosted: Thu Jun 10, 2004 5:47 pm    Post subject: Reply with quote

I haven't done anymore work since, but am considering a possible merge to encompass the doctype plugin and my own method of handling XHTML mime-types. (maybe known as html_headers) Wink

If you have any more ideas of things that could be included to allow for a complete plugin in your eyes, feel free to post them here.

I'm am not by any means advanced in PHP or smarty authoring Embarassed so appreciate any help or guidance people feel they can give. Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP