-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "html_attributes" twig filter for easiely write attributes as objects #3760
Conversation
@@ -28,6 +28,14 @@ public function getFilters(): array | |||
{ | |||
return [ | |||
new TwigFilter('data_uri', [$this, 'dataUri']), | |||
new TwigFilter( | |||
'html_attributes', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks more like a function than a filter to me
extra/html-extra/HtmlExtension.php
Outdated
continue; | ||
} | ||
|
||
$htmlAttributes[] = $key . '="' . twig_escape_filter($environment, $value, 'html_attr') . '"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keys must be escaped too
@@ -79,6 +87,35 @@ public function dataUri(string $data, string $mime = null, array $parameters = [ | |||
|
|||
return $repr; | |||
} | |||
|
|||
/** | |||
* @param array{string, string|bool|int|float|null} $attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong type. array{string, string|bool|int|float|null}
means an array with 2 elements, with index 0 being a string and index 1 being string|bool|int|float|null
. Instead, you should use array<string, string|bool|int|float|null>
Closing in favor of #3930 (which has the |
Make sense. Thx @mpdude 👍 |
Example usage:
TODO