diff --git a/src/TwigComponent/src/Test/InteractsWithTwigComponents.php b/src/TwigComponent/src/Test/InteractsWithTwigComponents.php index 6de97629cc0..ede6a9aaac8 100644 --- a/src/TwigComponent/src/Test/InteractsWithTwigComponents.php +++ b/src/TwigComponent/src/Test/InteractsWithTwigComponents.php @@ -51,8 +51,8 @@ protected function renderTwigComponent(string $name, array $data = [], ?string $ $template = \sprintf('{%% component "%s" with data %%}', addslashes($name)); - foreach (array_keys($blocks) as $blockName) { - $template .= \sprintf('{%% block %1$s %%}{{ blocks.%1$s|raw }}{%% endblock %%}', $blockName); + foreach ($blocks as $blockName => $blockContent) { + $template .= \sprintf('{%% block %1$s %%}%2$s{%% endblock %%}', $blockName, $blockContent); } $template .= '{% endcomponent %}'; @@ -62,7 +62,6 @@ protected function renderTwigComponent(string $name, array $data = [], ?string $ ->createTemplate($template) ->render([ 'data' => $data, - 'blocks' => $blocks, ]) ); } diff --git a/src/TwigComponent/tests/Fixtures/Component/WithSlotsAndLimitedScope.php b/src/TwigComponent/tests/Fixtures/Component/WithSlotsAndLimitedScope.php new file mode 100644 index 00000000000..257d03fe468 --- /dev/null +++ b/src/TwigComponent/tests/Fixtures/Component/WithSlotsAndLimitedScope.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\UX\TwigComponent\Tests\Fixtures\Component; + +use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; + +/** + * @author Kevin Bond + */ +#[AsTwigComponent] +final class WithSlotsAndLimitedScope +{ +} diff --git a/src/TwigComponent/tests/Fixtures/templates/components/WithSlotsAndLimitedScope.html.twig b/src/TwigComponent/tests/Fixtures/templates/components/WithSlotsAndLimitedScope.html.twig new file mode 100644 index 00000000000..084980f815a --- /dev/null +++ b/src/TwigComponent/tests/Fixtures/templates/components/WithSlotsAndLimitedScope.html.twig @@ -0,0 +1,7 @@ +
+ {% with { outerScope } only %} + {% block content %}{% endblock %} + {% block slot1 %}{% endblock %} + {% block slot2 %}{% endblock %} + {% endwith %} +
diff --git a/src/TwigComponent/tests/Integration/ComponentFactoryTest.php b/src/TwigComponent/tests/Integration/ComponentFactoryTest.php index ab4639ad0de..0869782f112 100644 --- a/src/TwigComponent/tests/Integration/ComponentFactoryTest.php +++ b/src/TwigComponent/tests/Integration/ComponentFactoryTest.php @@ -261,7 +261,7 @@ public function testCannotGetConfigByNameForNonRegisteredComponent() * @testWith ["tabl", "Unknown component \"tabl\". Did you mean this: \"table\"?"] * ["Basic", "Unknown component \"Basic\". Did you mean this: \"BasicComponent\"?"] * ["basic", "Unknown component \"basic\". Did you mean this: \"BasicComponent\"?"] - * ["with", "Unknown component \"with\". Did you mean one of these: \"with_attributes\", \"with_exposed_variables\", \"WithSlots\"?"] + * ["with", "Unknown component \"with\". Did you mean one of these: \"with_attributes\", \"with_exposed_variables\", \"WithSlots\", \"WithSlotsAndLimitedScope\"?"] * ["anonAnon", "Unknown component \"anonAnon\". And no matching anonymous component template was found."] */ public function testCannotGetInvalidComponent(string $name, string $expectedExceptionMessage) diff --git a/src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php b/src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php index 1d2b78524c5..6c8b0620bdd 100644 --- a/src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php +++ b/src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php @@ -15,6 +15,7 @@ use Symfony\UX\TwigComponent\Test\InteractsWithTwigComponents; use Symfony\UX\TwigComponent\Tests\Fixtures\Component\ComponentA; use Symfony\UX\TwigComponent\Tests\Fixtures\Component\WithSlots; +use Symfony\UX\TwigComponent\Tests\Fixtures\Component\WithSlotsAndLimitedScope; use Symfony\UX\TwigComponent\Tests\Fixtures\Service\ServiceA; final class InteractsWithTwigComponentsTest extends KernelTestCase @@ -87,5 +88,7 @@ public static function withSlotsNameProvider(): iterable { yield ['WithSlots']; yield [WithSlots::class]; + yield ['WithSlotsAndLimitedScope']; + yield [WithSlotsAndLimitedScope::class]; } }