@@ -395,17 +395,29 @@ use the ``render()`` helper::
395395 namespace App\Controller;
396396
397397 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
398+ use Symfony\Component\HttpFoundation\Response;
398399
399400 class ProductController extends AbstractController
400401 {
401402 public function index()
402403 {
403404 // ...
404405
406+ // the `render()` method returns a `Response` object with the
407+ // contents created by the template
405408 return $this->render('product/index.html.twig', [
406409 'category' => '...',
407410 'promotions' => ['...', '...'],
408411 ]);
412+
413+ // the `renderView()` method only returns the contents created by the
414+ // template, so you can use those contents later in a `Response` object
415+ $contents = $this->renderView('product/index.html.twig', [
416+ 'category' => '...',
417+ 'promotions' => ['...', '...'],
418+ ]);
419+
420+ return new Response($contents);
409421 }
410422 }
411423
@@ -446,19 +458,6 @@ the :class:`Twig\\Environment` class::
446458 }
447459 }
448460
449- Rendering a Template's Content
450- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
451- The ``renderView() `` method renders a template and returns its content. The content from the template can be used to create a ``Response `` object::
452-
453- use Symfony\Component\HttpFoundation\Response;
454-
455- $content = $this->renderView('product/index.html.twig', [
456- 'category' => '...',
457- 'promotions' => ['...', '...'],
458- );
459-
460- return new Response($content);
461-
462461Rendering a Template in Emails
463462~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
464463
0 commit comments