Skip to content

Commit 1003548

Browse files
committed
Reword
1 parent 7299acc commit 1003548

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

templates.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
462461
Rendering a Template in Emails
463462
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
464463

0 commit comments

Comments
 (0)