Answers.Body: <p>Whilst I can’t offer the exact template code for an answer right now as I am in bed (have I broke the stack rules?) it might be worth checking out the <code>|batch</code> filter. </p>
  
  <p>Or taking elements of this answer and making it suit your requirements <a href="https://craftcms.stackexchange.com/questions/19179/making-an-entry-grid-with-batch-2-3-2-in-row-then-3-in-row">Making an entry grid with Batch 2,3 (2 in row then 3 in row)</a></p>
  
  <p>And reading this <a href="https://twig.symfony.com/doc/2.x/filters/batch.html" rel="nofollow noreferrer">https://twig.symfony.com/doc/2.x/filters/batch.html</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-04T21:30:39.700Z
Answers.LastActivityDate: 2018-12-04T21:30:39.700Z
Answers.UserDisplayName: Mark
Body: <p>I have a structure called "Projects", which I am currently listing on a page. The layout looks like the below - with the every row starting or finishing with a <code>.wide</code> class thumbnail:</p>
  
  <p><a href="https://i.sstatic.net/qstIZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qstIZ.png" alt="Current layout"></a></p>
  
  <p>This is the code used to generate that layout (simpified here for clarity):</p>
  
  <pre><code>&lt;div class="image-link-grid"&gt;
    &lt;div class="container"&gt;
    {% for project in craft.entries.section('projects').all() %}
  
    {# Set a variable to check if it is a wide one or not #}
    {% set wide = 0 %}
    {% if (loop.index is divisible by(6) or loop.index0 is divisible by(6)) %}
      {% set wide = 1 %}
    {% endif %}
  &lt;div class="link-holder{% if wide %} wide{% endif %}"&gt;
    &lt;a href="{{ project.url }}" class="image-link"&gt;
      &lt;div class="info"&gt;
        &lt;h4&gt;{{ project.title }}&lt;/h4&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;/div&gt;
      {% endfor %}
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Some of the projects now have a lightswitch added (<code>project.story</code>) which makes them a "Story". These need to have a <code>.story</code> class added to them, and be injected into the layout every 6 entries, for as many as there are. Apart from that the standard project entries should list in the same order they appear in Craft. The Stories have a wider thumbnail image and some different content output in the listing.</p>
  
  <p>If there are more stories than standard entries they should then all list at the bottom, likewise if there are more standard entries these should list out. Below are images of those two scenarios:</p>
  
  <p><strong>1)</strong></p>
  
  <p><a href="https://i.sstatic.net/UNdEG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UNdEG.png" alt="Desired outcome 1"></a></p>
  
  <p><strong>2)</strong></p>
  
  <p><a href="https://i.sstatic.net/ICcBw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ICcBw.png" alt="Desired outcome 2"></a></p>
  
  <p>Can anyone please help with how I need to adjust my twig template to generate these layouts? I can add the <code>.story</code> class based on the lightswitch but am at a loss how to adapt the layout to have them appear where I need them to.</p>
  
  <p>Thanks for any help</p>
  
  <p>Mike</p>
  
Tags: <templating><craft3>
Title: Structure listing order & classes based on lightswitch value
ThreadText: # Structure listing order & classes based on lightswitch value
  
  (Asked by: username_0 on 2018-12-04)
  
  I have a structure called "Projects", which I am currently listing on a page. The layout looks like the below - with the every row starting or finishing with a `.wide` class thumbnail:
  
  [![Current layout](https://i.sstatic.net/qstIZ.png)](https://i.sstatic.net/qstIZ.png)
  
  This is the code used to generate that layout (simpified here for clarity):
  
  ```
  <div class="image-link-grid">
    <div class="container">
    {% for project in craft.entries.section('projects').all() %}
  
    {# Set a variable to check if it is a wide one or not #}
    {% set wide = 0 %}
    {% if (loop.index is divisible by(6) or loop.index0 is divisible by(6)) %}
      {% set wide = 1 %}
    {% endif %}
  <div class="link-holder{% if wide %} wide{% endif %}">
    <a href="{{ project.url }}" class="image-link">
      <div class="info">
        <h4>{{ project.title }}</h4>
      </div>
    </a>
  </div>
      {% endfor %}
    </div>
  </div>
  
  ```
  
  Some of the projects now have a lightswitch added (`project.story`) which makes them a "Story". These need to have a `.story` class added to them, and be injected into the layout every 6 entries, for as many as there are. Apart from that the standard project entries should list in the same order they appear in Craft. The Stories have a wider thumbnail image and some different content output in the listing.
  
  If there are more stories than standard entries they should then all list at the bottom, likewise if there are more standard entries these should list out. Below are images of those two scenarios:
  
  **1)**
  
  [![Desired outcome 1](https://i.sstatic.net/UNdEG.png)](https://i.sstatic.net/UNdEG.png)
  
  **2)**
  
  [![Desired outcome 2](https://i.sstatic.net/ICcBw.png)](https://i.sstatic.net/ICcBw.png)
  
  Can anyone please help with how I need to adjust my twig template to generate these layouts? I can add the `.story` class based on the lightswitch but am at a loss how to adapt the layout to have them appear where I need them to.
  
  Thanks for any help
  
  username_0
  
  **Tags:** templating, craft3
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-12-04. Score: 1
  
  Whilst I can’t offer the exact template code for an answer right now as I am in bed (have I broke the stack rules?) it might be worth checking out the `|batch` filter.
  
  Or taking elements of this answer and making it suit your requirements [Making an entry grid with Batch 2,3 (2 in row then 3 in row)](https://craftcms.stackexchange.com/questions/19179/making-an-entry-grid-with-batch-2-3-2-in-row-then-3-in-row)
  
  And reading this <https://twig.symfony.com/doc/2.x/filters/batch.html>
  
  
  ---
  
  