<p>You'll want to <a href="https://twig.symfony.com/doc/2.x/filters/split.html" rel="nofollow noreferrer">split</a> on the line breaks, then loop through the resulting array...</p>

<pre class="lang-html prettyprint-override"><code>{% for ingredient in listOfIngredients|trim|split('\n') %}
    &lt;li&gt;{{ ingredient }}&lt;/li&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-08-21T04:55:57.490Z
2017-08-21T04:55:57.490Z
Lindsey D
<p>I'm trying to get a list from a simple plain text field which will accept line breaks. I need to find a way to wrap an li tag around the content on that line. So everytime I hit enter, it wraps <code>&lt;li&gt;Whatever is on that line&lt;/li&gt;</code></p>

<p>So going from this:</p>

<p><a href="https://i.sstatic.net/ajxdM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ajxdM.png" alt="enter image description here"></a></p>

<p>Into this:</p>

<p><a href="https://i.sstatic.net/vf1Sm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vf1Sm.png" alt="enter image description here"></a></p>

<p>Thanks!</p>

<templating><field><twigextension>
How to get a list item <li> using a plain text field every time I hit enter
# How to get a list item <li> using a plain text field every time I hit enter

(Asked by: username_0 on 2017-08-21)

I'm trying to get a list from a simple plain text field which will accept line breaks. I need to find a way to wrap an li tag around the content on that line. So everytime I hit enter, it wraps `- Whatever is on that line`

So going from this:

[![enter image description here](https://i.sstatic.net/ajxdM.png)](https://i.sstatic.net/ajxdM.png)

Into this:

[![enter image description here](https://i.sstatic.net/vf1Sm.png)](https://i.sstatic.net/vf1Sm.png)

Thanks!

**Tags:** templating, field, twigextension

---

## 1 answers

### Answer by username_1 on 2017-08-21. Score: 4 | Accepted answer

You'll want to split on the line breaks, then loop through the resulting array...
{% for ingredient in listOfIngredients|trim|split('\n') %}
    {{ ingredient }}
{% endfor %}


---

