{% extends "_layout" %} {% block content %} {% cache %}

Company / Recognition

Recent design and engineering awards

Years

{# I love craft because the templating language is so expressive, but it does lead to a big ball of WTF... #} {# Here were getting the highest year set for any award, also the lowest year. The base year needs to be set as well for scope reasons. #} {% set topYear = craft.entries({ section: "awards", order: "awardYear desc", limit: "1", }).first().awardYear %} {% set bottomYear = craft.entries({ section: "awards", order: "awardYear asc", limit: "1", }).first().awardYear %} {% set baseYear = 1 %} {# We are using this loop to figure out what our base year is. Essentially what is the closest year, ending in ***0 or ***5, that is directly below our topYear #} {% for i in 1..5 %} {% if (topYear - i) % 5 == 0 %} {% set baseYear = topYear - i %} {% endif %} {% endfor %} {# Now we're figuring out how many times we need to loop to hit all our award years #} {% set remainder = (topYear - bottomYear) % 5 %} {% set loopCount = ceil(((topYear - bottomYear) / 5)) %} {% if remainder == 0 %} {% set loopCount = loopCount + 1 %} {% endif %}

{# The actual loop displaying the years #} {% for i in 1..loopCount %} {# It's slightly different for this first iteration because we want to show the topYear #} {% if i == 1 %} {{ baseYear }}–{{ topYear }} {% else %} {{ baseYear - (5 * i) + 5 }}–{{ baseYear - (5 * i) + 9 }} {% endif %}
{% endfor %}

View all
{% if craft.request.segment(3) %} {% set yearBottom = craft.request.segment(3) %} {% set yearTop = craft.request.segment(4) %} {% else %} {% set yearBottom = baseYear %} {% set yearTop = topYear %} {% endif %} {% for year in yearTop..yearBottom %} {% set awards = craft.entries.section("awards").awardYear(year) %} {% if awards | length > 0 %}

{{ year }}

{% for award in awards %} {% include "_includes/company/recognition/award" %} {% endfor %}
{% endif %} {% endfor %}
{% endcache %} {% endblock %}