I have a scenario where I'm using a Matrix to store and output 'sponsored links' for a page. Each link also has a radio button to select whether to display in a left hand column or a right hand column group.
Filtering like this is simple enough:
<div class='left'>
<h2>LEFT COLUMN TITLE</h2>
{% for sponsor in sponsors.sponsors %}
{% if sponsor.grouping == "Left column" %}
<li>
<a href="{{ sponsor.sponsorUrl }}"><img src="{{ sponsor.sponsorLogo.first().getUrl('maxwidth220') }}" alt="{{ sponsor.sponsorName }}" /></a>
</li>
{% endif %}
{% endfor %}
</div>
...
<div class='right'>
<h2>RIGHT COLUMN TITLE</h2>
{% for sponsor in sponsors.sponsors %}
{% if sponsor.grouping == "Right column" %}
<li>
<a href="{{ sponsor.sponsorUrl }}"><img src="{{ sponsor.sponsorLogo.first().getUrl('maxwidth220') }}" alt="{{ sponsor.sponsorName }}" /></a>
</li>
{% endif %}
{% endfor %}
</div>
This works, but it will always spit out a wrapping div and section heading, even if there is no content. How do I test to see if there's anything to spit out first?