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.

General Questions

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

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

Ajax Content Template


Reply

2 Posts   1950 Views

Avatar
Ben_W

21 December 2009 at 1:26pm (Last edited: 21 December 2009 1:31pm), Community Member, 80 Posts

http://doc.silverstripe.org/doku.php?id=recipes:ajax_basics
The above doc explain the basic usage of ajax in silverstripe site. The two example it presents, the first one is a static message gets displayd in the ajaxContent area, whereas the second one is image rendered in by ajaxSnippet template, and I did notice you can put some dynamic element, such as $Title inside the template.

What I would like to know is, if I need to display a collection of page's summary in the ajaxContent, how do I did it with a template?
ie: $eventPages = DataObject::get('EventPage', 'ParentID=$this->ID', '', '', '')

I need a template for the ajax content, so that I could style it.

if I do the following, I miss the opportunity of using renderWith,
if($this->isAjax) {
   return $eventPages;
//return "this is a test for ajax";
} else {
return Array();
}

I certainly can not do this, because I need to return a data object set, not just a static template.
if($this->isAjax) {
return $this->renderWith("ajaxSnippet");
}
else {
return Array();
}

I have also try the following, sort of merge the two, but failed
if($this->isAjax) {
return $EventPages->renderWith("ajaxSnippet");
}
else {
return Array();
}

Avatar
Fuzz10

25 December 2009 at 1:15am Community Member, 787 Posts

This :

f($this->isAjax) {
return $this->renderWith("ajaxSnippet");
}

in combination with a function to gather and return your dataobjects :

ie:

function GetEventPages () {
return DataObject::get('EventPage', 'ParentID=$this->ID', '', '', '')
}

and in your template :
<% control GetEventPages %>

$Title .. etc. etc.
<% end_control %>

good luck !