Skip to content

[TwigComponent] SyntaxError exception when using dashed attributes with HTML syntax #874

Closed
@ker0x

Description

@ker0x

I have a Modal component in which I include another Button component with data-* attributes to control the modal

{# Modal.html.twig #}

<twig:Button :class="btn_toggle_class" :data-modal-target="id" :data-modal-toggle="id">
    {{- btn_toggle_label|trans -}}
</twig:Button>
<div{{ attributes.defaults({
    id: id,
    'data-modal-placement': placement.value,
    tabindex: '-1',
    'aria-hidden': 'true',
    class: 'fixed top-0 left-0 right-0 z-50 hidden w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0 h-[calc(100%-1rem)] max-h-full'
}) }}>
    
</div>

When the component is rendered, I get a SyntaxError exception.

If i replace data-* attribute with a camelCase syntax ( :dataModalTarget="id"), the attribute is displayed in lower case (datamodaltarget="id")

Screenshot 2023-05-15 at 12-21-12 A hash key must be followed by a colon ( )  Unexpected token operator of value - ( punctuation expected with value )  (500 Internal Server Error)

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