use Symfony\Component\HttpFoundation\JsonResponse; $data = ['message' => 'Hello, World!']; $response = new JsonResponse($data); $response->send();
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Templating\Renderer\PhpRenderer; use Symfony\Component\Templating\TemplateNameParser; $renderer = new PhpRenderer(new TemplateNameParser()); $content = $renderer->render('template.php', [ 'name' => 'John Smith' ]); $response = new Response($content); $response->send();In this example, we are using the Symfony Templating component to render a template called `template.php` and passing a variable `$name` as data. We are then creating a new instance of the Response class with the rendered content and sending it to the client. This example uses the `symfony/templating` and `symfony/http-foundation` packages.