Sepp Hofer Sepp Hofer - 1 month ago 12
Ajax Question

Silverstripe 3.4 load content via ajax / Shortcode issue

Shortcodes dont render correctly.

I am loading content via ajax into bootstrap-tabs.

calling ajax works.

routes are ok.

I've tried


No matter what i try, the shortcodes don't render. Please help.

class EventPage_Controller extends Page_Controller {

public function EventDetail(SS_HTTPRequest $request){


$group = DataObject::get_one('Group', "\"Code\" = 'eventgroup'");
$member = Member::currentUser();
if($member && $member->inGroup($group->ID)){

if($event = DataObject::get_by_id('Event', intval($request->param('eventID')))){

$eventDetail = array(
'EventTitle' => $event->Name,
'EventContent' => $event->Content

/* if( Director::is_ajax() ) {
//$return = array('Time' => $time);
return $this->renderWith('EventDetail', json_encode(array('EventContent' => $event->Content)));
//return $this->customise($eventDetail)->renderWith(array('EventDetail', 'Page'));
//echo $event->Content;

echo json_encode(array('error' => '0', 'EventContent' => $event->Content));



$('.event-detail-btn').on('click', function(e){
var eventID = $(this).parent().attr('id').split('_')[1];
var dateID = $(this).parent().attr('id').split('_')[2];
//alert(eventID + '_' + dateID);
getEventDetail(eventID, dateID);
$('#event-detail, #member-enrolment').toggle();

function getEventDetail(eventID, dateID){

//$('#eventDetail').load('Enrolment/EventDetail/'+ eventID + '/' +dateID);

type: "POST",
url: 'Enrolment/EventDetail/'+ eventID + '/' +dateID,
dataType: "json"

<div id="enrolments" class="tab-pane fade">

<% include EventDetail %>
<% include MemberEnrolments %>

</div> <!--end enrolments-->

<div id="event-detail">
<a href="#"><button type="button" class="event-detail-btn btn btn-default btn-sm">zurück</button></a>

<div id="eventDetail"></div>

<a href="#"><button type="button" class="event-detail-btn btn btn-default btn-sm">zurück</button></a>

enter image description here

wmk wmk

Shortcodes are not automatically rendered when you're not calling them from a template, try:

$eventDetail = array(
    'EventTitle' => $event->Name,
    'EventContent' => $event->Content->forTemplate() //this is a HTMLText

or on SS3.4:

$eventDetail = array(
    'EventTitle' => $event->Name,
    'EventContent' => $event->Content->RAW() //this is a HTMLText

If this still doesn't work you might do it the hard way and call ShortcodeParser manually:


Also, you might use Director::is_ajax() to check if it's really an ajax call and output the ajax response or - as a fallback - the whole page including ajax content. See lessons or docs