AJAX renderWith doesn't render anything

Silverstripe Version: 4.8

In a controller that extends PageController I’m attempting to return some HTML partials to an XHR (jQuery GET) request.

Result:

image

The response the XHR sees is always empty for activeFilters and results. I’ve used the whole ProductListPage to return with the same result. Nothing rendered.

Reloading the page (to avoid the ajax) and it all works as expected.

I’ve also set one of them to <h1>hello</h1> and that does return correctly.

What have I forgotten? It’s like the renderWith isn’t actually doing a render.

Also to test, I changed the names of those includes to ones that don’t exist and it throws an error so I assume it’s at least finding them

Looks like SilverStripe templates don’t render unless explicitly return'd from the controller.

Bummer. Seems like a punishing limitation for XHR requests.

Would be good to know if there’s any way to force a render/process on a template into a variable like above.

This is not true: you can render whenever you want, as you have already done in your code. I do that myself all the time.

Sorry but I do not see any issue in the code you posted.

@ntd

I did get it to work, I had to add ->RAW() to the end of the renderWith() calls

You might find it also works if you cast to a string, eg.

$activeFilters => (string) $this->customise($data)->renderWith('Includes/ActiveFilters')