Jump to:

23478 Posts in 18950 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Ajax Content Template

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

Page: 1
Go to End
Author Topic: 1928 Views
  • Ben_W
    Avatar
    Community Member
    80 Posts

    Ajax Content Template Link to this post

    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();
    }

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Ajax Content Template Link to this post

    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 !

    1928 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.