Answers.Body: <p>You can split an array using the <a href="https://twig.symfony.com/doc/3.x/filters/slice.html" rel="nofollow noreferrer">slice filter</a>. This is useful if you need the two parts in separate places, this way you don't have to iterate through the entire array both times. Slice accepts two arguments, an offset and a length, and returns a new array with the specified number of items starting at the offset.</p>
  <pre class="lang-twig prettyprint-override"><code>{% set chunk_1 = array|slice(0, 4) %}
  {% set chunk_2 = array|slice(4, 6) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-17T10:00:33.770Z
Answers.Text: Thanks  Moritz. Do you think that will load faster and with less server resources than loop.index?
Answers.UserDisplayName: Markus Busch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-17T10:14:11.570Z
Answers.Text: @MarkusBusch Depends on how you're using the array elements in your template. But honestly, it doesn't matter. With ten array elements, you're talking about miliseconds. Use whichever version is easier to understand and modify in the context of your templates.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-17T09:45:00.443Z
Answers.LastActivityDate: 2021-12-17T09:45:00.443Z
Answers.UserDisplayName: MoritzLost
Answers.Body: <p>You can use Twig's <code>loop.index</code> variable to find out where you are within a for loop.</p>
  <p>i.e.</p>
  <pre><code>{% for entry in entries %}
  
      [...code to show entry...]
  
      {% if loop.index == 4 %}
          [...code to show image...]
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-17T09:56:43.127Z
Answers.Text: Works like a charm. Thank you & greetings from Switzerland!
Answers.UserDisplayName: Markus Busch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-16T19:53:38.377Z
Answers.LastActivityDate: 2021-12-16T19:53:38.377Z
Answers.UserDisplayName: stevecomrie
Body: <p>How do I split a list of 10 entries into two parts - one part with 4 entries, followed by an image section, and then the second part with 6 entries.</p>
  <p>Thanks for your help. markus</p>
  
Tags: <entry><query>
Title: Split a list of entries in two parts
ThreadText: # Split a list of entries in two parts
  
  (Asked by: username_0 on 2021-12-16)
  
  How do I split a list of 10 entries into two parts - one part with 4 entries, followed by an image section, and then the second part with 6 entries.
  
  Thanks for your help. username_0
  
  **Tags:** entry, query
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-12-17. Score: 2
  
  You can split an array using the [slice filter](https://twig.symfony.com/doc/3.x/filters/slice.html). This is useful if you need the two parts in separate places, this way you don't have to iterate through the entire array both times. Slice accepts two arguments, an offset and a length, and returns a new array with the specified number of items starting at the offset.
  
  ```twig
  {% set chunk_1 = array|slice(0, 4) %}
  {% set chunk_2 = array|slice(4, 6) %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks  Moritz. Do you think that will load faster and with less server resources than loop.index?  
  > **username_1**: @username_0 Depends on how you're using the array elements in your template. But honestly, it doesn't matter. With ten array elements, you're talking about miliseconds. Use whichever version is easier to understand and modify in the context of your templates.  
  
  ---
  
  ### Answer by username_2 on 2021-12-16. Score: 0
  
  You can use Twig's `loop.index` variable to find out where you are within a for loop.
  
  i.e.
  
  ```
  {% for entry in entries %}
  
      [...code to show entry...]
  
      {% if loop.index == 4 %}
          [...code to show image...]
      {% endif %}
  
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Works like a charm. Thank you & greetings from Switzerland!  
  
  ---
  
  