Replacing linebreak in Textarea to <br/> doesn't work

Viewed 43

On my Symfony website, when i send a comment like this:

line 1
line 2
line 3

It is displayed like this:

line 1 line 2 line 3

So i found this answer and this one but they didn't solve my question: I added nl2br to my code but the printed result is like this:

line 1<br /> line 2<br /> line 3

Here my code that i will simplify as follow:

Here my article.html.twig:

    {% for comment in comments|reverse %}
      <h4>{{ comment.title }}</h4>
      <p>{{ comment.message }}</p>
    {% endfor %}
    <h4>Leave your message</h4>
    {{ form(formComment) }}

So here my Comment.php:

public function getMessage(): ?string {
  return $this->message;
}

public function setMessage(string $message): self {
  $this->message = nl2br($message);  //nl2br is in test
  return $this;
}

Here my CommentType.php:

class CommentType extends AbstractType {
public function buildForm( FormBuilderInterface $builder,array $options): void {
  $builder
    ->add('title')
    ->add('message') //Here
    ->add('send', SubmitType::class);
}
0 Answers
Related