<p>Would this work?</p>

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

&lt;h2&gt;All teams in {{entry.title}}&lt;/h2&gt;
{% for team in teams %}
    &lt;h3&gt;{{team.title}}&lt;/h3&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-04-07T09:41:32.700Z
Thank Jamie it does work!
Seems like I underestimated craft :D
Marco Schuler
CC BY-SA 3.0
2016-04-07T09:26:30.357Z
2016-04-07T09:26:30.357Z
Jamie Pittock
<p>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.</p>

<p>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)?</p>

<p>location/_entry.html :</p>

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

{% block content %}
  &lt;article&gt;
    &lt;h2&gt;Studios in {{entry.title}}&lt;/h2&gt;
    {% for studio in studios %}
      &lt;h3&gt;{{studio.title}}&lt;/h3&gt;
    {% endfor %}

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

<templating><relations>
Prettiest way to loop through nested relations?
# Prettiest way to loop through nested relations?

(Asked by: username_0 on 2016-04-07)

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 %}
  
    Studios in {{entry.title}}
    {% for studio in studios %}
      {{studio.title}}
    {% endfor %}

    All teams in {{entry.title}}
      {% for studio in studios %}
      {% for team in craft.entries.section('team').relatedTo(studio) %}
        {{team.title}}
      {% endfor %}
    {% endfor %}
  
{% endblock %}

**Tags:** templating, relations


---

## 1 answers

### Answer by username_1 on 2016-04-07. Score: 4 | Accepted answer

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

All teams in {{entry.title}}
{% for team in teams %}
    {{team.title}}
{% endfor %}

> **Comments:**
> **username_0**: Thank Jamie it does work! Seems like I underestimated craft :D  

---

