Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Multiple DataObject in Template issue.

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

Page: 1
Go to End
Author Topic: 1466 Views
  • timwjohn
    Avatar
    Community Member
    98 Posts

    Multiple DataObject in Template issue. Link to this post

    Hi,

    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 Sectors.ss file in my theme folder:

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

    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.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Multiple DataObject in Template issue. Link to this post

    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 Page_sectors.ss, 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!.

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Multiple DataObject in Template issue. Link to this post

    Hey Willr, thanks for getting back to me.

    Actually my mistake, the file is called Carousel.ss, 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 Page.ss template and layout file would it? They're as stripped down as they can get.

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Multiple DataObject in Template issue. Link to this post

    Ah ha!

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

    1466 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.