Silverstripe Version: 4.1
In a controller responding to an AJAX request I have:
return $this->customise(['Apples' => $Apples])->renderWith('Includes/Apples');
That works. This:
return json_encode([
'Apples' => $this->customise(['Apples' => $Apples])->renderWith('Includes/Apples'),
'Something' => 'Some other partial'
]);
Doesn’t. Inspecting the response in dev tools shows Apples is empty {}. It’s not empty.
I’ve tried:
Adding
$this->response->addHeader('Content-Type', 'application/json');
Wrapping it in ArrayData
return new ArrayData([
'Apples' => $this->customise(['Apples' => $Apples])->renderWith('Includes/Apples'),
]));
Wrapping it in json_encode
return json_encode(new ArrayData([
'Apples' => $this->customise(['Apples' => $Apples])->renderWith('Includes/Apples'),
])));
Setting the partial to a variable first
$html = $this->customise(['Apples' => $Apples])->renderWith('Includes/Apples');
return json_encode([
'Apples' => $html,
'Something' => 'Some other partial'
]);
None of it works. The closest to working is the very first one, normal array wrapped in json_encode. That at least sends a response like: {“Apples”:{}}
What am I missing?