How to render a text with linebreak saved from a textarea form? Unfortunately I haven't found anything on the web with this specific problem.

I have a field (text, formatted, long) and a form with a textarea element that should save the entered text to this field.

Now I want to render it in my twig template. I access the value like this in my controller:

'text' =&gt; $node-&gt;field_text-&gt;value


And I render it in twig normally:

&lt;p&gt;{{ text }}&lt;/p&gt;


But whenever I entered a new line by pressing enter in the textarea, it doesn't render the new line. The same thing in the CKEditor when I edit the node and look at the content, there's no new line.


I'm sure that there's a linebreak though, because when I dpm() this value, it prints that.

I tried putting the value in a '#markup' =&gt; $text render array, but it was the same. How can I render this new line?
I tried putting the value in a '#markup' =&gt; $text render array, but it
  was the same. How can I render this new line?


Yes, you need to put the text in a render element, but for a formatted text field the correct element is processed_text:

'text' =&gt; [
  '#type' =&gt; 'processed_text',
  '#text' =&gt; $node-&gt;field_text-&gt;value,
  '#format' =&gt; $node-&gt;field_text-&gt;format,
],