I'm having real problems with renderWith. I'm trying to use it within a controller's init() method to return a different version of the page if it is requested using ajax.
public function init() {
parent::init();
...
if (Director::is_ajax()) {
return $this->renderWith(array('AjaxImagesPage'));
}
}
But... when it renders (and I've checked debug_request and showtemplate to observe this) it seems to first spit it all out using AjaxImagesPage, but then override it all, change it's mind, and just go through the normal rendering sequence. The result is that the ajax-requested page is identical to the normal - not the goal!
I've tried to think of workarounds (a different controller method, or an api-style approach with totally different urls for the ajax calls), but I really need this functionality - a page site/mypage to render differently for standard and ajax requests.
Thanks.