Skip to content
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

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

Open
ThomasLandauer opened this issue Feb 19, 2025 · 0 comments
Open

Comments

@ThomasLandauer
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant