Skip to content

Commit 3995385

Browse files
committed
[Template] Render a block with the #[Template] attribute
1 parent f1c7127 commit 3995385

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

templates.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,27 @@ This might come handy when dealing with blocks in
632632
:ref:`templates inheritance <template_inheritance-layouts>` or when using
633633
`Turbo Streams`_.
634634

635+
Similarly, you can use the ``#[Template]`` attribute on the controller to specify a block
636+
to render::
637+
638+
// src/Controller/ProductController.php
639+
namespace App\Controller;
640+
641+
use Symfony\Bridge\Twig\Attribute\Template;
642+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
643+
use Symfony\Component\HttpFoundation\Response;
644+
645+
class ProductController extends AbstractController
646+
{
647+
#[Template('product.html.twig', block: 'price_block')]
648+
public function price(): array
649+
{
650+
return [
651+
// ...
652+
];
653+
}
654+
}
655+
635656
Rendering a Template in Services
636657
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
637658

0 commit comments

Comments
 (0)