twigphp / twigphp/Twig

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

Open
#4,588 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
8.4k
Forks
1.3k
Avg merge
1d 13h
Merged PRs (30d)
37

Description

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: https://github.com/twigphp/Twig/issues/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: https://github.com/symfony/symfony/pull/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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Twig's nl2br filter and any tests covering its output. Compare the requested option with PHP's nl2br() $use_xhtml argument, and resolve whether the change targets Twig 3 or 4. Done means the filter can produce either
or
without breaking existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.