Skip to content

Instantly share code, notes, and snippets.

@1stevengrant
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1stevengrant/86b62353a2bb740c1441 to your computer and use it in GitHub Desktop.
Save 1stevengrant/86b62353a2bb740c1441 to your computer and use it in GitHub Desktop.
This code loops through sessions that are set as a workshop, groups them by workshop round, orders them by title and lists the related speaker for a session
{% set allWorkshops = craft.entries.section('session').sessionType('Workshop').order('sessionRound','title') %}
{% set allWorkshopsByRound = allWorkshops|group('sessionRound') %}
{% for round, workshopsInRound in allWorkshopsByRound %}
<h3 class="round">Round {{ round }}</h3>
{% for entry in workshopsInRound %}
{% set speaker = entry.sessionSpeaker.first() %}
<div class="talk">
<h4>{% for speaker in entry.sessionSpeaker %}{{ speaker.speakerFirstName }} {{ speaker.title }}{% if not loop.last %}, {% endif %}{% endfor %} | {{ entry.title }}</h4>
{{ entry.sessionOverview }}
</div>
<!-- // .talk -->
{% endfor %}
{% endfor %}
</div>
@jeromecoupe
Copy link

Looks good to me. What is bothering you ?

  • Would simplify it a bit by beeing explicit about the group filter
  • Would explicitly set asc, desc for order
  • Would check there is actually a speaker using the length filter
{% set allWorkshops = craft.entries.section('session').sessionType('Workshop').order('sessionRound asc', 'title desc') %}

{% for round, workshopsInRound in allWorkshops|group('sessionRound') %}

    <h3 class="round">Round {{ round }}</h3>

    {% for entry in workshopsInRound %}
        {% set speaker = entry.sessionSpeaker.first() %}
        <div class="talk">
            <h4>{% if speaker|length %}{{ speaker.speakerFirstName }} {{ speaker.title }} | {% endif %}{{ entry.title }}</h4>
            {{ entry.sessionOverview }}
        </div>
    {% endfor %}

{% endfor %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment