Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Themes /

Discuss SilverStripe Themes.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

xml declaration and browsers


Go to End


2 Posts   1997 Views

Avatar
jufemaiz

Community Member, 2 Posts

15 January 2009 at 4:15pm

Hi all,
new to the world of SilverStripe, though I'd have to say I'm liking what I'm seeing to date. That said, I'm discovering very quickly that one of my favourite methods of ensuring xml doctype is present where it should be won't work and am looking for a workaround.

Normally, at the top of my file I'll add this for PHP applications (I have a similar check of Rails apps). So my question is, what would be my step for how I would be able to do something like this?

<?php
	if(!preg_match('/MSIE\s(6\.0|5\.5|5\.0|5\.23);\s(Windows|Mac)/i', $_SERVER['HTTP_USER_AGENT'], $match))
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>

Avatar
Nivanka

Community Member, 400 Posts

15 January 2009 at 5:22pm

This can be accomplished by adding a method to the Page_Controller class.

edit your mysite/code/Page.php like the following.


<?php

class Page extends SiteTree {
   .......

}

class Page_Controller extends ContentController {
	function init() {
		.........
	}
    
	function AddCheck() {
		if(!preg_match('/MSIE\s(6\.0|5\.5|5\.0|5\.23);\s(Windows|Mac)/i', $_SERVER['HTTP_USER_AGENT'], $match))
                   return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 
                else
                   return "what you need to return, if you dont want to return anything, just return false";
	}
}


?>

then add the following on your Page.ss on the relavant template, if it is BlackCandy do this on the /themes/blackcandy/templates/Page.ss


<% if AddCheck %>
    $AddCheck
<% end_if %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >

..........