[TwigComponent] Nicer syntax and imports
Now that the html like syntax is supported I'd like to propose to enhance a little bit further to introduce import_component or something similar so we can use aliased or direct component names without prefix, for example:
{% import_component 'App\Component\Alert' %}
{# or #}
{% import_component 'App\Component\Alert' as MyAlert %}
to use as:
<Alert />
or
<MyAlert />
My 2 cents: I'm not sold that this is needed, but I'm also not "unsold" either :p
For frontenders at least it would be a little similar when going into twig land from js :)
Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature?
For sure
Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature? Every feature is developed by the community. Perhaps someone would like to try? You can read how to contribute to get started.
Hi, I'm not really fan of this kind of feature, in the JavaScript world, you can import and alias through the module resolution system, which does not exist here with Twig Components.
Twig Components are globally registered, if you want an alias, then I believe that you can configure an alias in AsTwigComponent attribute.
Yes but what about the anonymous component @Kocal ?
Not a fan either, if I take your example for #1108 with <twig:Form:Button:PrimaryButton>, I rather think that it's a design problem on your part, and UX shouldn't try to fix it.
From my point of view, having a PrimaryButton component under Form/Button folders is totally overkill, and PrimaryButton can easily be remplaced by Button variant="primary" (by using html_cva that you introduced in the ecosystem 😉).
I believe you can write <twig:Form:Button variant="primary"></twig:Form:Button> or even simpler <twig:Button variant="primary"></twig:Button> instead.
It would only work outside component and not inside
{% import Foo:Bar as Bar %}
{# would work #}
<twig:Bar />
<twig:Blop>
{# would probably not work #}
<twig:Bar />
</twig:Blop>
This is a much harder thing that it seems to many...
So personnaly I'm not sure i will discuss this without some concrete implementation attempt that keep all the existing features with no conflict, BC or performance issue.
Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature? Every feature is developed by the community. Perhaps someone would like to try? You can read how to contribute to get started.