<p>Seems like a huge hack to me but here's how to do it:</p>
<pre><code>{# Split paragraphs using with a limit of 3 #}
{% set paragraphs = text|split('&lt;/p&gt;', 3) %}

{# Get an array containing the first 2 paragraphs, and convert it back to a string, adding missing closing tags  #}
{% set firstParagraphs = paragraphs|slice(0, -1)|join('&lt;/p&gt;') ~ '&lt;/p&gt;' %}

{{ firstParagraphs|raw }}

{# The rest of the text is here, due to the limit in the split filter #}
{{ paragraphs|last|raw }}
</code></pre>
<p>To adjust the number of paragraphs in your first group, just change the <code>limit</code> parameter of the <code>join</code> twig filter (this is a bit counter intuitive, see the <a href="https://twig.symfony.com/doc/2.x/filters/split.html" rel="nofollow noreferrer">Twig documentation</a> to understand the logic).</p>

CC BY-SA 4.0
2020-09-04T04:53:18.773Z
By limit do you mean split? How would I change this to pull five paragraphs for example? Not following how split(0, -1) works. Thanks!
univers_
CC BY-SA 4.0
2020-09-04T08:05:25.073Z
`split` is a Twig Filter that takes a mandatory parameter (the delimiter) and an optional one (the limit). The limit limits the size of the array returned by the split filter.
Take a look at the split filter documentation (https://twig.symfony.com/doc/2.x/filters/split.html), I have no idea how to explain it better.
nstCactus
CC BY-SA 4.0
2020-09-03T11:31:16.270Z
2020-09-03T11:31:16.270Z
nstCactus
<p>The below is code that works to only show the first paragraph, then show the rest. Is it possible to instead, show the first five or six paragraphs, then show the rest?</p>
<pre><code>{# Split paragraphs using a limit of 2 #}
{% set paragraphs = block.body|split('&lt;/p&gt;', 2) %}

{# Get first paragraph and add the missing closing tag  #}
{% set firstParagraph = paragraphs|first ~ '&lt;/p&gt;' %}

{{ firstParagraph|raw }}

{# The rest of the text is here, due to the limit in the split filter #}
{{ paragraphs|last|raw }}
</code></pre>
<p>Wordsmith works for this, but I'm unable to see a way to output the rest of the paragraphs.</p>

<templating><text>
Get first X paragraphs, then output the rest
# Get first X paragraphs, then output the rest

(Asked by: username_0 on 2020-09-02)

The below is code that works to only show the first paragraph, then show the rest. Is it possible to instead, show the first five or six paragraphs, then show the rest?
{# Split paragraphs using a limit of 2 #}
{% set paragraphs = block.body|split('', 2) %}

{# Get first paragraph and add the missing closing tag  #}
{% set firstParagraph = paragraphs|first ~ '' %}

{{ firstParagraph|raw }}

{# The rest of the text is here, due to the limit in the split filter #}
{{ paragraphs|last|raw }}

Wordsmith works for this, but I'm unable to see a way to output the rest of the paragraphs.

**Tags:** templating, text

---

## 1 answers

### Answer by username_1 on 2020-09-03. Score: 1 | Accepted answer

Seems like a huge hack to me but here's how to do it:
{# Split paragraphs using with a limit of 3 #}
{% set paragraphs = text|split('', 3) %}

{# Get an array containing the first 2 paragraphs, and convert it back to a string, adding missing closing tags  #}
{% set firstParagraphs = paragraphs|slice(0, -1)|join('') ~ '' %}

{{ firstParagraphs|raw }}

{# The rest of the text is here, due to the limit in the split filter #}
{{ paragraphs|last|raw }}

To adjust the number of paragraphs in your first group, just change the limit parameter of the join twig filter (this is a bit counter intuitive, see the Twig documentation to understand the logic).

> **Comments:**
> **username_0**: By limit do you mean split? How would I change this to pull five paragraphs for example? Not following how split(0, -1) works. Thanks!  
> **username_1**: `split` is a Twig Filter that takes a mandatory parameter (the delimiter) and an optional one (the limit). The limit limits the size of the array returned by the split filter. Take a look at the split filter documentation (https://twig.symfony.com/doc/2.x/filters/split.html), I have no idea how to explain it better.  

---

