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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Special .ss Template for XML Version of Page

Go to End

3 Posts   1555 Views


Community Member, 197 Posts

24 August 2010 at 1:27pm

HTML versions of page on my website can be accessed at URLs like this:

I also want each page to be available in XML format at URLs like this:

Now "" is used as the HTML template.

I want "" should be used as the template for the XML version of pages.


Community Member, 904 Posts

25 August 2010 at 6:48pm

Shouldn't be too difficult.
First you need a special rewrite-rule:

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule (.*)\.xml$ sapphire/main.php?url=$1/xml [L,QSA]
	RewriteCond %{REQUEST_URI} ^(.*)$
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]

The red part is what's newly added.

Then add the following function to your Page_Controller:

public function xml(){
	return array();

And now all that is left to do is to create a special template for that. You have to name it and put it in your templates folder.

Calling /page.xml?flush=1 should now render your page with the XML template.


Community Member, 78 Posts

14 June 2011 at 12:37am

Hi Bana,

I am sorry to disturb you, I was trying to generate the record from DataObject into XML format for using on my flash page.
I have NewsItem as DataObject with following code:

class NewsItem extends DataObject {

static $db = array(
'Title' => 'Varchar(255)',
'Details' => 'HTMLText',
'Source' => 'Varchar(255)',
'Date' => 'Date'
static $has_one = array(
'NewsPage' => 'NewsPage',
'NewsPhoto' => 'Image'
static $summary_fields = array(
'Title' => 'Title',
'Source' => 'Source',
'Date' => 'Date'

public function getCMSFields() {
return new FieldSet(
new TextField('Title'),
new SimpleTinyMCEField('Details', 'News Details'),
new TextField('Source', 'News Source'),
new DatePickerField('Date', 'Release Date'),
new ImageField('NewsPhoto', 'Photo', Null, Null, Null, 'Uploads/latest-news/photos/')

function caView() {
return true;

//Return the Name as a menu title
public function MenuTitle() {
return $this->Title;

public function Link() {
if ($NewsPage = $this->NewsPage()) {
return $NewsPage->Link('show/') . $this->ID;

public function LinkingMode() {
if ($Controller = Controller::CurrentPage() && Controller::CurrentPage()->ClassName == 'NewsPage') {
if (Controller::CurrentPage()->getAction() == 'show' && $NewsItem = Controller::CurrentPage()->getNewsItem()) {
return ($NewsItem->ID == $this->ID) ? 'current' : 'link';


my purpose i would like to generate all record from this DataObject into XML Format, you have any example, I am trying many way but it return 404 error.

Your replies I really appreciated.