3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1352 Views |
-
Multiple DataObject in Template issue.

30 March 2010 at 4:43am
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.
-
Re: Multiple DataObject in Template issue.

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 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!.
-
Re: Multiple DataObject in Template issue.

30 March 2010 at 11:55am
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.
-
Re: Multiple DataObject in Template issue.

30 March 2010 at 1:02pm
You'd have to hit home/sectors if you do as Will says: "One thing you could try is name the template Page_sectors.ss, and restructure your PHP like ..."
Otherwise try:
http://site.url/Page_Controller/sectorsHope this helps.
- Luke -
Re: Multiple DataObject in Template issue.

31 March 2010 at 6:58am
Ah ha!
Sorted. It was a matter of adding 'sectors' to the $allowed_actions array.
| 1352 Views | ||
|
Page:
1
|
Go to Top |



