短代码无法正确渲染。
我通过ajax将内容加载到bootstrap-tabs。
调用ajax工作。
路线还可以。
我已尝试renderWith()
,customise()
....
无论我尝试什么,短代码都不会呈现。请帮忙。
class EventPage_Controller extends Page_Controller {
public function EventDetail(SS_HTTPRequest $request){
if($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 $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));
}
}
}
}
的javascript:
$('#event-detail').hide();
$('.event-detail-btn').on('click', function(e){
//alert('click');
e.stopPropagation();
e.preventDefault();
if($(this).parent().is('tr')){
//alert('TR');
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);
$.ajax({
type: "POST",
url: 'Enrolment/EventDetail/'+ eventID + '/' +dateID,
dataType: "json"
}).success(function(msg){
$('#eventDetail').html(msg.EventContent);
});
}
Page.ss
<div id="enrolments" class="tab-pane fade">
<% include EventDetail %>
<% include MemberEnrolments %>
</div> <!--end enrolments-->
EventDetail.ss
<div id="event-detail">
<br><br>
<a href="#"><button type="button" class="event-detail-btn btn btn-default btn-sm">zurück</button></a>
<br><br>
<div id="eventDetail"></div>
<a href="#"><button type="button" class="event-detail-btn btn btn-default btn-sm">zurück</button></a>
</div>
答案 0 :(得分:1)
如果您未从模板中调用短代码,则不会自动呈现短代码,请尝试:
$eventDetail = array(
'EventTitle' => $event->Name,
'EventContent' => $event->Content->forTemplate() //this is a HTMLText
);
或SS3.4:
$eventDetail = array(
'EventTitle' => $event->Name,
'EventContent' => $event->Content->RAW() //this is a HTMLText
);
如果仍然无法正常工作,您可能会采取艰难的方式并手动拨打ShortcodeParser
:
ShortcodeParser::get_active()->parse($event->Content);
此外,您可以使用Director::is_ajax()
检查它是否真的是ajax调用并输出ajax响应,或者 - 作为后备 - 整个页面包含ajax内容。请参阅lessons或docs