Skip to content

Suggestion: Add $use_xhtml to |nl2br to switch from <br /> to <br> #4588

@ThomasLandauer

Description

@ThomasLandauer

Twig's |nl2br filter outputs <br />. The HTML validator discourages this:

Info: Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.

Switching to <br> has been suggested before: #1306
But it wouldn't be a good idea anyway, since a similar PR for <input /> got reverted later, due to issues with some HTML parser: symfony/symfony#47715

So, new suggestion to eventually get rid of those unnecessary slashes: ;-)
PHP's nl2br() function has an argument $use_xhtml to toggle between <br> and <br />. So just add this to Twig and everybody should be happy :-)

I could try to create a PR. For v3 or 4?

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