I have a bit of a problem that I don't understand at all.
Neither the property "selected" nor one of the methods "selected()", "getselected()"/"isselected()"/"hasselected()" or "__call()" exist and have public access in class "App\Twig\Components\MenuItem".
Selected property is well and beautifully defined and in public. I don't know what the problem is
//
<?php
namespace App\Twig\Components;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent]
final class MenuItem
{
public string $selected;
}
:class="{'rotate-180': (selected ==='{{ this.selected }}')}"
></i>
</a>
{% else %}
<a
x-init="console.log('{{ this.selected }}')"
When creating
TwigComponentsyou don't need to do{{ this.var }}to reference the variable created in the PHP class, you can just use{{ var }}.Changing your code to
{{ selected }}instead of{{ this.selected }}should resolve the issue.