symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony

Home Page:https://ux.symfony.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[TwigComponent] Passing HTML to Components Via Blocks Is Not Possible With Variable Component Name

kickingRaccoon opened this issue · comments

Hello Teams & Thanks for the works on Twig Components (Amazing !!!)

I m try to do a library for my components and i need to call them dynamicaly:

{% set component = 'My:Component' %°} {# I don t really do that in my template ... #}
{{ component(component) }}

and it works great !!!

but for particular component i need to set some inner HTML:

{% set component = 'My:Component' %°}
{% component(component)  with my_args%}
    <div>...</div>
{% endcomponent %}

and then 💥 :

Error rendering "component" component: Unknown component "component". And no matching anonymous component template was found.

It seems Symfony\UX\TwigComponent\Twig\ComponentTokenParser::componentName() does not parse the variable but simply render the name of the NameExpression (there's no compiling of the NameExpression ...)

There is another way to do that or it 's simply a bug or it's intentional ?

Thank you for the response and for all

Embedded component names need to be resolved before runtime, so it wont work in your second example indeed.

Thanks
I will try another way ... 😢