I'm using Zurb foundation's Block Grid and using this in a matrix field where users can (using a block called 'wrapper') add a row and define the number of columns which appear side by side across a desktop device in that row, then using another block 'textBlocks' add divs of text within the row. I also want to add an option of 'fullwidth' a lightswitch field in the 'wrapper' block, so if this is selected then the 'following' will wrap around the row:
<div class="fullwidth">
…row/text content
</div>
but I can't seem to add the closing in the right place (at the end of the row), code below:
{% set isWrapperOpen = false %}
{% for block in entry.pagedesigner %}
{% switch block.type %}
{% case "wrapper" %}
{% if block['fullwidth'] is defined %}<div class="fullwidth">{% endif %}
{% if isWrapperOpen %}</div>{% endif %}
<div class="row large-up-{{ block.columns }}">
{% set isWrapperOpen = true %}
{{ block.heading }}
{% case "textBlocks" %}
<div class="column">
{{ block.text }}
</div>
{% endswitch %}
{% if loop.last and isWrapperOpen %}</div>{% endif %}
{% endfor %}
Appreciate semantics need some work but need to figure logic first
UPDATE I've since chatted with Andrew Fairlie from Mutual and got this working (with his guidance) excuse the crude inline styles – just helps aid making visual sense to me :)
{% set isWrapperOpen = false %} {% set isFullWrapperWidthOpen = false %} {% for block in entry.pageDesigner %}
{% switch block.type %}
{% case "wrapper" %}
{# Close the previous fullwidth wrapper before we open a new one #}
{% if isFullWrapperWidthOpen %}</div>{% endif %}
{# Close the previous wrapper before we open a new one #}
{% if isWrapperOpen %}</div>{% endif %}
{% if block.fullWidth %}
{% set isFullWrapperWidthOpen = true %}
<div class="row expanded" style="background-color: red; margin-bottom: 30px;">
{% else %}
{% set isFullWrapperWidthOpen = false %}
{% endif %}
<div class="row large-up-{{ block.columns }}">
{% set isWrapperOpen = true %}
{% case "heading" %}
<h2 style="background-color: blue;" class="column text-{{ block.position }} heading heading--{{ block.size }}">
{{ block.text }}
</h2>
{% case "textBlocks" %}
<div class="column" style="background-color: yellow;">
{{ block.text }}
</div>
{% endswitch %}
{# If we're on the last block, close up the last wrapper div #} {% if loop.last and isWrapperOpen %}{% endif %} {% if loop.last and isFullWrapperWidthOpen %}**{% endif %} {% endfor %}