Answers.Body: <p>Do you mean to have it just assign them one after the other? If so, then you can just use <a href="https://twig.symfony.com/doc/2.x/functions/cycle.html" rel="nofollow noreferrer">Twig’s <code>cycle</code> function</a>.</p>
  
  <pre><code>{% set themes = [
      'yellow',
      'red',
      'teal',
      'blue'
  ] %}
  
  {% for region in regions %}
   &lt;a href="{{ region.url }}" class="text-{{ cycle(themes, loop.index) }}"&gt;{{ region.title }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-02T20:31:06.787Z
Answers.Text: This worked: `{{ cycle(themes, loop.index) }}`. Thanks, mate!
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-02T20:38:09.877Z
Answers.Text: Ah, good catch! That’ll teach me to write from my meatbrain and not refer to the docs. I’ve updated the response accordingly, including documentation.
Answers.UserDisplayName: Christopher Kennedy-Nuñez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-04T16:22:10.743Z
Answers.Text: Another update, the array starts at 0 whilst the loop started at 1... so `loop.index - 1` was needed to start from the start. ‍♂️
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-04T21:40:37.480Z
Answers.Text: Ah, true. You don’t need to use math, though. You can just use `loop.index0` instead!
Answers.UserDisplayName: Christopher Kennedy-Nuñez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-02T20:08:42.710Z
Answers.LastActivityDate: 2019-12-02T20:35:19.363Z
Answers.LastEditDate: 2019-12-02T20:35:19.363Z
Answers.UserDisplayName: Christopher Kennedy-Nuñez
Body: <p>I have a loop of a list of regions on a project, this could be an infinite list of areas as my client's customer-base grows.</p>
  
  <p>The project branding has four key colours, I have these in an array:</p>
  
  <pre><code>{% set themes = [
      'yellow',
      'red',
      'teal',
      'blue'
  ] %}
  </code></pre>
  
  <p>What I'm looking to do is grab one of these themes as I loop over my regions with a basic <code>{% for region in regions %}</code>, then on the 5th, 9th and so on loop jump back to #1.</p>
  
Tags: <templating><loop><array>
Title: Reuse items from array with forloop
ThreadText: # Reuse items from array with forloop
  
  (Asked by: username_0 on 2019-12-02)
  
  I have a loop of a list of regions on a project, this could be an infinite list of areas as my client's customer-base grows.
  
  The project branding has four key colours, I have these in an array:
  
  ```
  {% set themes = [
      'yellow',
      'red',
      'teal',
      'blue'
  ] %}
  
  ```
  
  What I'm looking to do is grab one of these themes as I loop over my regions with a basic `{% for region in regions %}`, then on the 5th, 9th and so on loop jump back to #1.
  
  **Tags:** templating, loop, array
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-12-02. Score: 2 | Accepted answer
  
  Do you mean to have it just assign them one after the other? If so, then you can just use [Twig’s `cycle` function](https://twig.symfony.com/doc/2.x/functions/cycle.html).
  
  ```
  {% set themes = [
      'yellow',
      'red',
      'teal',
      'blue'
  ] %}
  
  {% for region in regions %}
   <a href="{{ region.url }}" class="text-{{ cycle(themes, loop.index) }}">{{ region.title }}</a>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: This worked: `{{ cycle(themes, loop.index) }}`. Thanks, mate!  
  > **username_1**: Ah, good catch! That’ll teach me to write from my meatbrain and not refer to the docs. I’ve updated the response accordingly, including documentation.  
  > **username_0**: Another update, the array starts at 0 whilst the loop started at 1... so `loop.index - 1` was needed to start from the start. ‍♂️  
  > **username_1**: Ah, true. You don’t need to use math, though. You can just use `loop.index0` instead!  
  
  ---
  
  