Skip to content

Commit a8cebf3

Browse files
committed
[Twig] add a component name/template "namespace" notation
1 parent 5f484d6 commit a8cebf3

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/TwigComponent/src/Resources/doc/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ as the second argument to the ``AsTwigComponent`` attribute:
190190
// ...
191191
}
192192
193+
Twig Template Namespaces
194+
~~~~~~~~~~~~~~~~~~~~~~~~
195+
196+
You can use a ``/`` in your component's name to indicate a template namespace.
197+
For example, a component with the name ``form/input`` will look for a template
198+
in ``templates/components/form/input.html.twig``.
199+
193200
The mount() Method
194201
~~~~~~~~~~~~~~~~~~
195202

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\TwigComponent\Tests\Fixtures\Component;
13+
14+
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
15+
16+
#[AsTwigComponent('foo/bar/baz')]
17+
final class NamespacedComponent
18+
{
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Content...

src/TwigComponent/tests/Integration/ComponentExtensionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ public function testCanRenderEmbeddedComponent(): void
130130
$this->assertStringContainsString('custom td (1)', $output);
131131
}
132132

133+
public function testComponentWithNamespace(): void
134+
{
135+
$output = $this->renderComponent('foo/bar/baz');
136+
137+
$this->assertStringContainsString('Content...', $output);
138+
}
139+
133140
private function renderComponent(string $name, array $data = []): string
134141
{
135142
return self::getContainer()->get(Environment::class)->render('render_component.html.twig', [

0 commit comments

Comments
 (0)