symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
856 stars 315 forks source link

[LiveComponent] Inheritance in live components #2217

Closed tito10047 closed 1 month ago

tito10047 commented 1 month ago

It would be nice if you could inherit live component from normal component.

{# templates/components/Alert.html.twig #}
<div {{ attributes.defaults({class: 'alert alert-'~type}) }}">
    {% block content %}{% endblock %}
</div>
{# templates/components/SuccessAlertLiveComponent.html.twig #}
{% component Alert with attributes.defaults({class:"foo"}) %}
    {{ block(outerBlocks.content) }}
{% endcomponent %}

Is something like this possible?

smnandre commented 1 month ago

LiveComponent have no knowledge of their "outerblocks" so it would not work during re-render

tito10047 commented 1 month ago

Yes, of course. Stupid example copied from docs. I have problem only with this "with attributes.defaults({class:"foo"})" . With this I get parse error

smnandre commented 1 month ago

Can you maybe show the code that triggers this error?

smnandre commented 1 month ago

Oh i'm sorry i did not pay enough attention..

You cannot pass "attributes" like this, as it is not a mapping/array but a special object, and it is required to be renderered in its template :/

Let's say you want do the same for Twig Components... then you could use with {attributes: attributes.defaults( ...) } or with attributes.defaults(...).toArray()

tito10047 commented 1 month ago

Yes, that is what I means. Thanks :)