Skip to content

Instantly share code, notes, and snippets.

@bryantAXS
Created September 3, 2014 23:28
Show Gist options
  • Save bryantAXS/e23852bc320559b8f1d3 to your computer and use it in GitHub Desktop.
Save bryantAXS/e23852bc320559b8f1d3 to your computer and use it in GitHub Desktop.
{% extends "_layout" %}
{% block content %}
{% cache %}
<!-- content container -->
<div class="small-12 large-10 columns body-white">
<!-- template specific data -->
<div data-template="recognition"></div>
<script>
var template = 'recognition';
</script>
<!-- intro -->
<div class="row content-intro">
<div class="large-9 large-offset-1 columns">
<h3>Company / Recognition</h3>
<h1>Recent design and engineering awards</h1>
</div>
</div>
<!-- content bucket -->
<div class="row content-container">
<div class="large-10 large-offset-1 columns">
<div class="row">
<div class="large-3 columns recognition-sidebar">
<h3>Years</h3>
{#
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 %}
<p>
{#
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 %}
<a href="/company/recognition/{{ baseYear }}/{{ topYear }}">
{{ baseYear }}&ndash;{{ topYear }}
</a>
{% else %}
<a href="/company/recognition/{{ baseYear - (5 * i) + 5 }}/{{ baseYear - (5 * i) + 9 }}">
{{ baseYear - (5 * i) + 5 }}&ndash;{{ baseYear - (5 * i) + 9 }}
</a>
{% endif %}
<br>
{% endfor %}
</p>
<a class="view-all" href="#">View all</a>
</div>
<div class="large-9 columns">
<div class="row">
{% 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 }} -->
<div class="large-12 columns recognition-timeframe">
<h3>{{ year }}</h3>
{% for award in awards %}
{% include "_includes/company/recognition/award" %}
{% endfor %}
</div><!-- timeframe -->
{% endif %}
{% endfor %}
</div><!-- row -->
</div><!-- large -->
</div>
</div><!-- large-10 -->
</div><!-- row -->
</div><!-- small-12 -->
{% endcache %}
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment