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:

Data Model Questions /

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

Multiple DataObject in Template issue.

Go to End

4 Posts   1900 Views


Community Member, 98 Posts

30 March 2010 at 4:43am


I would like my SilverStripe templates to output XML that my Flash front end can connect to. It seems I've fallen at the first hurdle. Been reading other forum posts but they all seem to refer to getting only one object, and even so it just ain't working for me. It seems so simple, but I just can't crack it!

First things first: I have a Sector DataObject, and want to list them all in XML. So in my basic Page_controller I've got:

class Page_Controller extends ContentController implements PermissionProvider 
    public function sectors()
        $sectors = DataObject::get('Sector');
        if ($sectors)
            return $this->customise(array('CarouselItems' => $sectors))->renderWith('Carousel');
        return false;

Then I have a file in my theme folder:

    <% control CarouselItems %>
        <item id="$ID" name="$Name">
    <% end_control %>

I'm keeping it simple for now, but there will be more stuff to populate the item node in control block.

When I visit /home/sectors (home being the default page) I get a 404. I'm using 2.4beta-2.


Forum Moderator, 5523 Posts

30 March 2010 at 10:42am

Perhaps the issue is because you are defining renderWith('Carousel') but your template is called Sectors?. Also note for templates like this they have to be in templates/ not the templates/Layout/ folder or includes.

One thing you could try is name the template, and restructure your PHP like

public function CarouselItems()  { 
return DataObject::get('Sector'); 

Then visit home/sectors/ I know this will work with 2.4,can't remember if this will work with 2.3 but you could try!.


Community Member, 98 Posts

30 March 2010 at 11:55am

Hey Willr, thanks for getting back to me.

Actually my mistake, the file is called, and it is in templates/ not templates/layout/

With this being the case can you think of any other reason why I'd be getting a 404? I'll need to take an 'ID' parameter from the URL to customise the output, plus create other functions for different categories and whatnot, so I'd be using getParam(s) and more cutomised DataObject::gets. Ideally I'd have all the functions in my basic page controller.

It wouldn't be anything to do with my template and layout file would it? They're as stripped down as they can get.


Community Member, 98 Posts

31 March 2010 at 6:58am

Ah ha!

Sorted. It was a matter of adding 'sectors' to the $allowed_actions array.