Skip to content

[TwigComponent] Hyphen-separated attributes don't work with HTML syntax #851

Closed
@AmProsius

Description

@AmProsius

I have a component that accepts any HTML attribute in addition to other props:

{# templates/components/IconMini.html.twig #}

<svg
  xmlns="http://www.w3.org/2000/svg"
  viewBox="0 0 20 20"
  fill="currentColor"
  {{ attributes.defaults({
    class: 'h-5 w-5',
  }) }}
>
  {# ... #}
</svg>

But if I pass hyphen-separated HTML attributes like aria-* or data-*, I get the following error: A hash key must be followed by a colon (:). Unexpected token "operator" of value "-" ("punctuation" expected with value ":").

{# templates/_navbar.html.twig #}

<twig:IconMini name="chevron-down" aria-hidden="true" />

The component syntax works fine:

{# templates/_navbar.html.twig #}

{{ component('IconMini', {
  name: 'chevron-down',
  'aria-hidden': 'true',
}) }}

Other than that, I absolutely love the new HTML Syntax!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions