1

Let’s say i have a location channel, a studio and a team channel. A location contains one or several studios and a studio contains one or several teams. I can display all the teams in a location by looping through all the studios related to the location and then through all the teams related to the studio.

Is it somehow possible to do that in one loop? To only loop through all the teams related to the location ( which aren’t related directly to each other)?

location/_entry.html :

{% set studios = craft.entries.section('studio').relatedTo(entry) %}

{% block content %}
  <article>
    <h2>Studios in {{entry.title}}</h2>
    {% for studio in studios %}
      <h3>{{studio.title}}</h3>
    {% endfor %}

    <h2>All teams in {{entry.title}}</h2>
      {% for studio in studios %}
      {% for team in craft.entries.section('team').relatedTo(studio) %}
        <h3>{{team.title}}</h3>
      {% endfor %}
    {% endfor %}
  </article>
{% endblock %}
4

Would this work?

{% set teams = craft.entries.section('team').relatedTo(studios) %}

<h2>All teams in {{entry.title}}</h2>
{% for team in teams %}
    <h3>{{team.title}}</h3>
{% endfor %}
| improve this answer | |
  • Thank Jamie it does work! Seems like I underestimated craft :D – Marco Schuler Apr 7 '16 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.