ux icon indicating copy to clipboard operation
ux copied to clipboard

[TwigComponent] Nicer syntax and imports

Open norkunas opened this issue 2 years ago • 6 comments

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  />

norkunas avatar Apr 17 '23 04:04 norkunas

My 2 cents: I'm not sold that this is needed, but I'm also not "unsold" either :p

weaverryan avatar Apr 17 '23 14:04 weaverryan

For frontenders at least it would be a little similar when going into twig land from js :)

norkunas avatar Apr 17 '23 14:04 norkunas

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?

carsonbot avatar Apr 25 '24 12:04 carsonbot

For sure

norkunas avatar Apr 25 '24 12:04 norkunas

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.

carsonbot avatar Oct 26 '24 12:10 carsonbot

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.

Kocal avatar Oct 26 '24 12:10 Kocal

Yes but what about the anonymous component @Kocal ?

WebMamba avatar Nov 01 '24 18:11 WebMamba

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.

Kocal avatar Nov 01 '24 18:11 Kocal

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.

smnandre avatar Nov 01 '24 18:11 smnandre

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.

carsonbot avatar Jul 06 '25 12:07 carsonbot