Answers.Body: <p>One way I have achieved this is like so:</p>
  
  <pre><code>{% for entry in artists %}
    {% if loop.first %}
      &lt;div class="flex flex-wrap items-center"&gt;
    {% endif %}
    {% if loop.index == 5 %}
      &lt;/div&gt;
      &lt;div class="flex flex-wrap items-center lg:ml-20"&gt;
    {% endif %}
    &lt;figure class="w-1/4 sm:w-100px mb-0 border border-white"&gt;
      {% include '_includes/_components/image.twig' with {
        image: entry.artistImage[0],
        alt: 'Artists',
        transform: 'square',
        classes:'w-full',
        sizes:'(min-width:576px), 100px, 25vw',
        widthEnd: 800
      } %}
    &lt;/figure&gt;
    {% if loop.last %}
      &lt;/div&gt;
    {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>But I think this circumvents the issue rather than solves the question. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-16T11:14:27.107Z
Answers.LastActivityDate: 2019-04-16T11:14:27.107Z
Answers.UserDisplayName: Terry Upton
Body: <p>So I want to get 9 random entries from a section and I do this like so:</p>
  
  <pre><code>{% set artists = craft.entries
    .section('artists')
    .artistImage(':notempty:')
    .with(['artistImage'])
    .orderBy('RAND()')
    .limit(9) %}
  </code></pre>
  
  <p>Now I want to split these entries into a row of 4 and a row of 5. I am doing this like so:</p>
  
  <pre><code>&lt;div class="flex flex-wrap items-center"&gt;
    {% for entry in artists|slice(0, 4) %}
      &lt;figure class="w-1/4 sm:w-100px mb-0 border border-white"&gt;
        {% include '_includes/_components/image.twig' with {
          image: entry.artistImage[0],
          alt: 'Artists',
          transform: 'square',
          classes:'w-full',
          sizes:'(min-width:576px), 100px, 25vw',
          widthEnd: 800
        } %}
        {{ entry.title }}
      &lt;/figure&gt;
    {% endfor %}
  &lt;/div&gt;
  
  &lt;div class="flex flex-wrap items-center lg:ml-20"&gt;
    {% for entry in artists|slice(4) %}
      &lt;figure class="w-1/5 sm:w-100px mb-0  border border-white"&gt;
        {% include '_includes/_components/image.twig' with {
          image: entry.artistImage[0],
          alt: 'Artists',
          transform: 'square',
          classes:'w-full',
          sizes:'(min-width:576px), 100px, 20vw',
          widthEnd: 800
        } %}
        {{ entry.title }}
      &lt;/figure&gt;
    {% endfor %}
  </code></pre>
  
  <p>However, this seems to randomise the each split and sometimes I get duplicate entries in each split.</p>
  
  <p>Ideally, I want to get 9 random items and then keep this order and split this into to separate rows.</p>
  
  <p>How can I achieve this? </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-16T11:24:48.320Z
Comments.Text: if you use .all() on the query doesn't that set the order of the array returned so the slice will work on the array rather than the query (which is deprecated behaviour anyway right?)?
Comments.UserDisplayName: billythekid
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-17T08:43:39.783Z
Comments.Text: Yes you are correct @billythekid - I had missed off the .all() - still getting used to adding that.
Comments.UserDisplayName: Terry Upton
Tags: <templating><entries><array>
Title: Get random entries from a section but keep the order of these when splitting the array
ThreadText: # Get random entries from a section but keep the order of these when splitting the array
  
  (Asked by: username_0 on 2019-04-16)
  
  So I want to get 9 random entries from a section and I do this like so:
  
  ```
  {% set artists = craft.entries
    .section('artists')
    .artistImage(':notempty:')
    .with(['artistImage'])
    .orderBy('RAND()')
    .limit(9) %}
  
  ```
  
  Now I want to split these entries into a row of 4 and a row of 5. I am doing this like so:
  
  ```
  <div class="flex flex-wrap items-center">
    {% for entry in artists|slice(0, 4) %}
      <figure class="w-1/4 sm:w-100px mb-0 border border-white">
        {% include '_includes/_components/image.twig' with {
          image: entry.artistImage[0],
          alt: 'Artists',
          transform: 'square',
          classes:'w-full',
          sizes:'(min-width:576px), 100px, 25vw',
          widthEnd: 800
        } %}
        {{ entry.title }}
      </figure>
    {% endfor %}
  </div>
  
  <div class="flex flex-wrap items-center lg:ml-20">
    {% for entry in artists|slice(4) %}
      <figure class="w-1/5 sm:w-100px mb-0  border border-white">
        {% include '_includes/_components/image.twig' with {
          image: entry.artistImage[0],
          alt: 'Artists',
          transform: 'square',
          classes:'w-full',
          sizes:'(min-width:576px), 100px, 20vw',
          widthEnd: 800
        } %}
        {{ entry.title }}
      </figure>
    {% endfor %}
  
  ```
  
  However, this seems to randomise the each split and sometimes I get duplicate entries in each split.
  
  Ideally, I want to get 9 random items and then keep this order and split this into to separate rows.
  
  How can I achieve this?
  
  **Tags:** templating, entries, array
  
  > **Comments:**
  > **username_1**: if you use .all() on the query doesn't that set the order of the array returned so the slice will work on the array rather than the query (which is deprecated behaviour anyway right?)?  
  > **username_0**: Yes you are correct @username_1 - I had missed off the .all() - still getting used to adding that.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-04-16. Score: 1
  
  One way I have achieved this is like so:
  
  ```
  {% for entry in artists %}
    {% if loop.first %}
      <div class="flex flex-wrap items-center">
    {% endif %}
    {% if loop.index == 5 %}
      </div>
      <div class="flex flex-wrap items-center lg:ml-20">
    {% endif %}
    <figure class="w-1/4 sm:w-100px mb-0 border border-white">
      {% include '_includes/_components/image.twig' with {
        image: entry.artistImage[0],
        alt: 'Artists',
        transform: 'square',
        classes:'w-full',
        sizes:'(min-width:576px), 100px, 25vw',
        widthEnd: 800
      } %}
    </figure>
    {% if loop.last %}
      </div>
    {% endif %}
  {% endfor %}
  
  ```
  
  But I think this circumvents the issue rather than solves the question.
  
  
  ---
  
  