I'm in a situation where I have a handful of matrix blocks which have similar subfields. For example, I have a "Bios" block where there's an intro etc., but the a few repeating fields, imagine:
- Bio 1 Name (bioName1)
- Bio 1 Image (bioImage1)
- Bio 2 Name (bioName2)
- Bio 2 Image (bioImage2)
- etc. up to 6
In my template, I have some pretty redundent code when outputting these fields, like:
{% if block.bioName1 %}
<div class="bit">
<div class="bio">
{% for asset in block.bioImage1 %}
<img src="{{ asset.url }}" alt="" />
{% endfor %}
<header>
<h3>{{ block.bioName1 }}</h3>
<p>{{ block.bioTitle1 }}</p>
</header>
{{ block.bioText1 }}
</div>
</div>
{% endif %}
{% if block.bioName2 %}
<div class="bit">
<div class="bio">
{% for asset in block.bioImage2 %}
<img src="{{ asset.url }}" alt="" />
{% endfor %}
<header>
<h3>{{ block.bioName2 }}</h3>
<p>{{ block.bioTitle2 }}</p>
</header>
{{ block.bioText2 }}
</div>
</div>
{% endif %}
I'm wondering if it would be possible to somehow set this up as a loop with a counter to increment the vars (the field names always end with the count)? Any ideas? I tried a few things but have had no luck :/