This is a strange one I've never come across over 5 years developing with EE. There may be a simple solution but I'm not seeing it!
Essentially, I need to create a dynamic loop that outputs a different colour background after each 2 entries. To help you understand, I have a full screen width background, inside there is a container with 2 entries. After these two, there is a new full width background with another 2 entries, then after those two, it reverts back to the original colour and so on...
This is my code:
<section class='section section-desktop'>
<div class="l-wrap">
<div class="l-grid">
{exp:channel:entries channel="partners" orderby="date" sort="asc"}{if partner_group == "Construction & Property"}<div class="l-grid__item-half">
{if partner_logo != ""}<img class="partner-logo partner-logo--large" src="{partner_logo}" alt="{title} logo">{if:else}
<div class="icon-construction-property content-icon" data-grunticon-embed></div>{/if}
<p><strong>Company Name:</strong> {title}</p>
<p><strong>Established:</strong> {partner_established}</p>
<p><strong>Key business activities:</strong></p>
{partner_key_business_activities}
{partner_additional_info}
{if partner_website_link != ""}<p><a class="btn" href="{partner_website_link}">Visit website</a></p>{/if}
</div><!--
-->{/if}{/exp:channel:entries}
</div>
</div>
</section>
All I need to do is add a class of "section--light-grey" to the main section class. Because this is outside the loop, I can't use {switch} or conditional counting.
Any idea how to do this without creating multiple loops with offset parameters? Or can I offset dynamically?
Here is a diagram of what I'm trying to achieve:
Entry 1 – Entry 2 (white background section)
Entry 3 – Entry 4 (light grey background section)
Entry 5 – Entry 6 (white background section)
Entry 7 – Entry 8 (light grey background section)
etc...