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

Ajax Content Template


Go to End


2 Posts   2715 Views

Avatar
Ben_W

Community Member, 80 Posts

21 December 2009 at 1:26pm

Edited: 21/12/2009 1:31pm

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

Community Member, 791 Posts

25 December 2009 at 1:15am

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 !