@@ -604,6 +604,52 @@ to define the template to render::
604
604
605
605
The ``#[Template()] `` attribute was introduced in Symfony 6.2.
606
606
607
+ The ``AbstractController `` also provides the
608
+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ AbstractController::renderBlock `
609
+ and :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ AbstractController::renderBlockView `
610
+ methods::
611
+
612
+ // src/Controller/ProductController.php
613
+ namespace App\Controller;
614
+
615
+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
616
+ use Symfony\Component\HttpFoundation\Response;
617
+
618
+ class ProductController extends AbstractController
619
+ {
620
+ // ...
621
+
622
+ public function price(): Response
623
+ {
624
+ // ...
625
+
626
+ // the `renderBlock()` method returns a `Response` object with the
627
+ // block contents
628
+ return $this->renderBlock('product/index.html.twig', 'price_block', [
629
+ // ...
630
+ ]);
631
+
632
+ // the `renderBlockView()` method only returns the contents created by the
633
+ // template block, so you can use those contents later in a `Response` object
634
+ $contents = $this->renderBlockView('product/index.html.twig', 'price_block', [
635
+ // ...
636
+ ]);
637
+
638
+ return new Response($contents);
639
+ }
640
+ }
641
+
642
+ This might come handy when dealing with blocks in
643
+ :ref: `templates inheritance <template_inheritance-layouts >` or when using
644
+ `Turbo Streams `_.
645
+
646
+ .. versionadded :: 6.4
647
+
648
+ The
649
+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ AbstractController::renderBlock ` and
650
+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ AbstractController::renderBlockView `
651
+ methods were introduced in Symfony 6.4.
652
+
607
653
Rendering a Template in Services
608
654
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
609
655
@@ -1131,6 +1177,8 @@ Use the ``attributes`` option to define the value of hinclude.js options:
1131
1177
set this option to 'true' to run that JavaScript code #}
1132
1178
{{ render_hinclude(controller('...'), {attributes: {evaljs: 'true'}}) }}
1133
1179
1180
+ .. _template_inheritance-layouts :
1181
+
1134
1182
Template Inheritance and Layouts
1135
1183
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1136
1184
@@ -1614,3 +1662,4 @@ for this class and :doc:`tag your service </service_container/tags>` with ``twig
1614
1662
.. _`official Twig extensions` : https://github.com/twigphp?q=extra
1615
1663
.. _`global variables` : https://twig.symfony.com/doc/3.x/advanced.html#id1
1616
1664
.. _`hinclude.js` : https://mnot.github.io/hinclude/
1665
+ .. _`Turbo Streams` : https://symfony.com/bundles/ux-turbo/current/index.html
0 commit comments