<p>You could also add the Twig <a href="http://twig.sensiolabs.org/doc/filters/raw.html"><code>raw</code></a> filter, which should prevent the automated escaping.</p>

<pre><code>{% set address = contact.address|nl2br|raw %}
</code></pre>

CC BY-SA 3.0
2014-09-30T13:56:29.680Z
Thanks for your answer, and this is what I ended up doing with a small difference because using `|nl2br` and `|raw` together didn't work. A bit strange though that the `|nl2br` filter would encode the `<br />`'s...
bravokiloecho
CC BY-SA 3.0
2016-08-30T18:44:13.797Z
found a solution?
william
CC BY-SA 3.0
2014-09-30T13:10:11.913Z
2014-09-30T13:21:22.770Z
2014-09-30T13:21:22.770Z
Pascal Mollet
<p>I'm using Craft v3.1, I noticed that none of the answers worked for me. </p>

<p>I only got it to work by placing <code>raw</code> before <code>nl2br</code>. </p>

<p>This is what worked for me: <code>{{ entry.customFieldName |raw|nl2br }}</code></p>

CC BY-SA 4.0
2019-02-03T19:23:45.923Z
2019-02-03T19:23:45.923Z
mateostabio
<p>Just using <code>|nl2br</code> inside a <code>&lt;p&gt;</code> tag (or whatever you choose) worked for me.</p>

<p><code>&lt;p&gt;{{ contact.address|nl2br }}&lt;/p&gt;</code></p>

CC BY-SA 3.0
2017-03-24T10:16:55.273Z
2017-03-24T10:16:55.273Z
Adam Menczykowski
<p>Add raw before nl2br</p>

<pre><code>{% set address = contact.address|raw|nl2br %}
</code></pre>

<p>This will work.</p>

CC BY-SA 4.0
2019-12-11T12:58:30.503Z
2019-12-11T12:58:30.503Z
Ash
<p>Expanding from <a href="https://craftcms.stackexchange.com/users/149/pascal-mollet">Pascal Mollet</a>'s answer, this was the solution I came up with.</p>

<p>First setting the address variable with the <code>|nl2br</code> filter:</p>

<pre><code>{% set address = contact.address|nl2br %}
</code></pre>

<p>Then, outputting that variable with the <code>|raw</code> filter:</p>

<pre><code>{{address|raw}}
</code></pre>

<p>Using them both together at once like this (as Pascal suggested):</p>

<pre><code>{% set address = contact.address|nl2br|raw %}
</code></pre>

<p>didn't work.</p>

CC BY-SA 3.0
2014-10-06T20:18:58.427Z
I was able to use @Pascal's suggestion successfully - though instead of setting the variable, I just printed out the code like so: `{{ contact.address|nl2br|raw }}`
Ray
CC BY-SA 3.0
2014-09-30T14:00:19.607Z
2014-10-01T08:01:57.390Z
2017-04-13T12:51:00.160Z
bravokiloecho
<p>I'm looking for a way to output line break from a text field.</p>

<p>I'm aware of the "Allow line breaks" option and I have set that to true. I've then entered text with multiple new lines. However, when this text gets output in the template, there are no line breaks.</p>

<p>I have tried using <a href="http://twig.sensiolabs.org/doc/filters/nl2br.html">Twig's new line to br function</a>, like this:</p>

<pre><code>{% set address = contact.address|nl2br %}
</code></pre>

<p>but this creates <code>&lt;br /&gt;</code> tags in the text, not the markup - that is, you can actually see the <code>&lt;br /&gt;</code> in the browser and no actual line breaks are being created.</p>

<p>Am I doing something wrong here? Are there any alternative solutions?</p>

<p>Thanks!</p>

<templating>
Create line breaks from text field
# Create line breaks from text field

(Asked by: username_0 on 2014-09-30)

I'm looking for a way to output line break from a text field.
I'm aware of the "Allow line breaks" option and I have set that to true. I've then entered text with multiple new lines. However, when this text gets output in the template, there are no line breaks.
I have tried using Twig's new line to br function, like this:
{% set address = contact.address|nl2br %}

but this creates  tags in the text, not the markup - that is, you can actually see the  in the browser and no actual line breaks are being created.
Am I doing something wrong here? Are there any alternative solutions?
Thanks!

**Tags:** templating

---

## 5 answers

### Answer by username_0 on 2014-09-30. Score: 32 | Accepted answer

Expanding from Pascal Mollet's answer, this was the solution I came up with.
First setting the address variable with the |nl2br filter:
{% set address = contact.address|nl2br %}

Then, outputting that variable with the |raw filter:
{{address|raw}}

Using them both together at once like this (as Pascal suggested):
{% set address = contact.address|nl2br|raw %}

didn't work.

> **Comments:**
> **username_6**: I was able to use @Pascal's suggestion successfully - though instead of setting the variable, I just printed out the code like so: `{{ contact.address|nl2br|raw }}`  

---

### Answer by username_1 on 2014-09-30. Score: 11

You could also add the Twig raw filter, which should prevent the automated escaping.
{% set address = contact.address|nl2br|raw %}

> **Comments:**
> **username_0**: Thanks for your answer, and this is what I ended up doing with a small difference because using `|nl2br` and `|raw` together didn't work. A bit strange though that the `|nl2br` filter would encode the `<br />`'s...  
> **username_2**: found a solution?  

---

### Answer by username_3 on 2019-02-03. Score: 2

I'm using Craft v3.1, I noticed that none of the answers worked for me.

I only got it to work by placing `raw` before `nl2br`.

This is what worked for me: `{{ entry.customFieldName |raw|nl2br }}`


---

### Answer by username_4 on 2017-03-24. Score: 2

Just using `|nl2br` inside a  tag (or whatever you choose) worked for me.

`{{ contact.address|nl2br }}`


---

### Answer by username_5 on 2019-12-11. Score: 1

Add raw before nl2br
{% set address = contact.address|raw|nl2br %}

This will work.


---

