tempest-framework icon indicating copy to clipboard operation
tempest-framework copied to clipboard

Dynamic components throw warnings in a foreach loop

Open wiegertschouten opened this issue 3 months ago • 0 comments

Tempest version

2.3.3

PHP version

8.4

Operating system

macOS

Description

I am trying to render a component dynamically in a loop. Outside of a loop, it works fine. But when I try to render the component in a loop, based on a variable which lives in the scope of that loop, I get a warning that the variable I am using is not defined. I tried several ways, but I can't get rid of the warning.

Maybe I'm overlooking something obvious, but I suspect it might be a bug.

Steps to reproduce

Create a controller method which returns this:

return view('home.view.php', components: [
    'x-component-1',
    'x-component-2'
]);

You also need two empty components, x-component-1.view.php and x-component-2.view.php. And a view that looks like this:

<!-- Works fine -->
<x-component :is="$components[0]" />

<x-template :foreach="$components as $component">

    <!-- Works fine too -->
    {{ lw($component) }}

    <!-- Warning: Undefined variable $component -->
    <x-component :is="$component" />

</x-template>

wiegertschouten avatar Oct 16 '25 18:10 wiegertschouten