I have some logic in a template where I want to count the number of items that have a lightswitch set to yes, and a radio button set to another value, currently I'm doing this via a series of {% set %} variables for loops and if statments, I just wondered if anyone know of a more efficient method to resolve this issue, or if this is the simplest implementation within Craft.
{% set normalNominations = 0 %}
{% set specialNominations = 0 %}
{% set normalWin = 0 %}
{% set specialWin = 0 %}
{% for items in entry.matrixloop %}
{% if items.type == "awardBody" %}
{% elseif items.type == "awardType" %}
{% if items.oscar %}
{% if items.awardGained == "Win" %}
{% set specialWin = specialWin + 1 %}
{% elseif items.awardGained == "Nomination" %}
{% set specialNominations = specialNominations + 1 %}
{% endif %}
{% else %}
{% if items.awardGained == "Win" %}
{% set normalWin = normalWin + 1 %}
{% elseif items.awardGained == "Nomination" %}
{% set normalNominations = normalNominations + 1 %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{# Debug Information #}
{#
<p> Special win: {{ specialWin }} </p>
<p> Special Nominations: {{ specialNominations }} </p>
<p> Normal Win: {{ normalWin }} </p>
<p> Normal Nomination: {{ normalNominations }} </p>
{{ entry.matrixloop | length }}
#}
Thanks in advance for your help with this, I'm pretty new to Craft so want to make sure I'm being efficient in my templates and not writing rubbish.
Ta
Dave