ux icon indicating copy to clipboard operation
ux copied to clipboard

[Twig] Add `attributes()` twig function

Open kbond opened this issue 1 year ago • 6 comments

Q A
Bug fix? no
New feature? no
Issues n/a
License MIT

This allows passing attributes to elements easier.

<div{{ attributes({foo: 'bar'})>

When/if #1413 is merged, the following will also be possible:

<twig:Some:Component {{ ...attributes({foo: 'bar'}) }} />

kbond avatar Jan 23 '24 00:01 kbond

Similar twig core issues/PRs: https://github.com/twigphp/Twig/pull/3930, https://github.com/twigphp/Twig/issues/3907, https://github.com/twigphp/Twig/pull/3760

kbond avatar Jan 23 '24 15:01 kbond

The function name attributes is unfortunate as it can be confused with the attributes parameter in twig/live components:

<div{{ attributes }}> {# correct #}

<div{{ attributes() }}> {# wrong #}

html_attr() maybe?

kbond avatar Jan 23 '24 17:01 kbond

That's a great idea, it would also close #940 since the main idea was to easily renders attributes

Kocal avatar Jan 23 '24 19:01 Kocal

The function name attributes is unfortunate as it can be confused with the attributes parameter in twig/live components:

Yes, I agree here. I like html_attr but also attr as it's proposed in the Twig issue.

How it's gonna work with Live components for example?

<div attributes({role: 'alert', class='text-blue-800 px-4',  ...attributes})>
...
</div>

WebMamba avatar Jan 23 '24 22:01 WebMamba

Would love to have this in Twig itself :)

norkunas avatar Jan 24 '24 08:01 norkunas