Hi all,
My goal is to get a piece of (rendered) HTML code inside a JSON response. Something like that:
Code:
{
"status": "success",
"html" : "<h1>Today is your birthday</h1>"
}
This is just an example, the real HTML is a little bit longer and has variables inside, so I need to create a view file.
In CI3 there is the third param flag this command to output the HTML as a string:
PHP Code:
$string = $this->load->view('you_view', $params, TRUE);
Now, I'm trying to understand how things are working in CI4 and choose the right way.
This is my code right now.
Is this the correct way or is there something that I'm missing (like the View Renderer)?
PHP Code:
$data = [
'api' => $this->api,
'formId' => $this->formId
];
$html = view('form_view', $data);
return $this->response->setJSON([
'status' => 'success',
'html' => $html
]);
Thanks for the advice.