Answers.Body: <p>The best way is to change home team ID and away team ID to entry fields that select the club. If you are using a plugin like Feed Me to bring in the matches, and you have all of the club IDs already entered in the club entries, you should be able to import matches and use the home and away IDs and match them to the appropriate Club in Feed Me.</p>
  
  <p>Once that is done, you won't have to loop through all of the Clubs, just pull the one from each of the matches home and away fields like so:</p>
  
  <pre><code>{% for team in fixture.homeTeamId.limit(1).all() %}
      {% for logo in team.clubLogo.limit(1).all() %}
          &lt;img src="{{ logo.getUrl() }}" /&gt;
      {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>If your API isn't brought in with Feed Me (or akin) and you can't change the home/away fields to entry selectable fields, you can select a team by matching its ID field to the given ID field like so:</p>
  
  <pre><code>{% set awayId = fixture.awayTeamId %}
  {% set awayTeam = craft.entries.section('clubs').search('clubId:'~awayId).limit(1) %}
    {% for team in awayTeam %}
      ...
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-14T13:47:24.287Z
Answers.Text: A perfect solution! Thank you so much Indigo - this works a treat.
Answers.UserDisplayName: Paddy Dewhurst
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-13T13:28:18.440Z
Answers.LastActivityDate: 2018-12-13T13:28:18.440Z
Answers.UserDisplayName: Chattervast
Body: <p>I have a site that shows upcoming football matches in a table, and I would like to include the clubs' logos next to each club name.</p>
  
  <p>I have the following sections and entry types, both generated using an API and feedme to create entries </p>
  
  <ul>
  <li><p>Teams section (includes fields for teamIDs and logos)</p></li>
  <li><p>Matches section (includes fields for home team &amp; home team ID, away team &amp; away team ID, match time and location, but does not include logos)</p></li>
  </ul>
  
  <p>The team ids and home/away team IDs match.</p>
  
  <p>To display logos, I imagine the process should go something like this:</p>
  
  <ul>
  <li>for each hometeam and awayteam in each row of the match table, identify the team ID</li>
  <li>Use the ID to find the related teams in the teams section, </li>
  <li>output the asset (logo) related teams logo in the match table.</li>
  </ul>
  
  <p>This feels like a relatedTo / reverse relations problem, where i can say - in twig - something like:</p>
  
  <p>{% if homeTeamId or awayTeamId in the fixtures section is the same as a Teamid field in the Team Section, then output that related teams's logo. %}</p>
  
  <p>Can anyone suggest the most efficient way to structure this in Twig?</p>
  
  <p><a href="https://i.sstatic.net/lo7Qr.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lo7Qr.png" alt="enter image description here"></a>
  <a href="https://i.sstatic.net/HBx12.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HBx12.png" alt="enter image description here"></a>
  <a href="https://i.sstatic.net/1oLBt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1oLBt.png" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-11T13:19:50.127Z
Comments.Text: Is the home team ID and away team ID fields just text fields? Or are they entry fields? Seems like you could just have an away and home team field in the matches section and just get the logo of the select team from those fields.
Comments.UserDisplayName: Chattervast
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-13T11:42:12.793Z
Comments.Text: Hi Indigo, Yes - the hometeam ID and awayteam ID are just text fields, and are already present in the matches section (sorry that was unclear).
  How would I get the logo of the selected team for this field? (note, the logo of the team is not stored in the match entry, only in the club entry. the reason is that the match data is imported from an API that doesn't include logos.)
Comments.UserDisplayName: Paddy Dewhurst
Tags: <templating><entries><assets><relations>
Title: Displaying related image assets from another section with twig
ThreadText: # Displaying related image assets from another section with twig
  
  (Asked by: username_0 on 2018-12-09)
  
  I have a site that shows upcoming football matches in a table, and I would like to include the clubs' logos next to each club name.
  
  I have the following sections and entry types, both generated using an API and feedme to create entries
  
  * Teams section (includes fields for teamIDs and logos)
  * Matches section (includes fields for home team & home team ID, away team & away team ID, match time and location, but does not include logos)
  
  The team ids and home/away team IDs match.
  
  To display logos, I imagine the process should go something like this:
  
  * for each hometeam and awayteam in each row of the match table, identify the team ID
  * Use the ID to find the related teams in the teams section,
  * output the asset (logo) related teams logo in the match table.
  
  This feels like a relatedTo / reverse relations problem, where i can say - in twig - something like:
  
  {% if homeTeamId or awayTeamId in the fixtures section is the same as a Teamid field in the Team Section, then output that related teams's logo. %}
  
  Can anyone suggest the most efficient way to structure this in Twig?
  
  [![enter image description here](https://i.sstatic.net/lo7Qr.png)](https://i.sstatic.net/lo7Qr.png)
  [![enter image description here](https://i.sstatic.net/HBx12.png)](https://i.sstatic.net/HBx12.png)
  [![enter image description here](https://i.sstatic.net/1oLBt.png)](https://i.sstatic.net/1oLBt.png)
  
  **Tags:** templating, entries, assets, relations
  
  > **Comments:**
  > **username_1**: Is the home team ID and away team ID fields just text fields? Or are they entry fields? Seems like you could just have an away and home team field in the matches section and just get the logo of the select team from those fields.  
  > **username_0**: Hi Indigo, Yes - the hometeam ID and awayteam ID are just text fields, and are already present in the matches section (sorry that was unclear). How would I get the logo of the selected team for this field? (note, the logo of the team is not stored in the match entry, only in the club entry. the reason is that the match data is imported from an API that doesn't include logos.)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-12-13. Score: 1 | Accepted answer
  
  The best way is to change home team ID and away team ID to entry fields that select the club. If you are using a plugin like Feed Me to bring in the matches, and you have all of the club IDs already entered in the club entries, you should be able to import matches and use the home and away IDs and match them to the appropriate Club in Feed Me.
  
  Once that is done, you won't have to loop through all of the Clubs, just pull the one from each of the matches home and away fields like so:
  
  ```
  {% for team in fixture.homeTeamId.limit(1).all() %}
      {% for logo in team.clubLogo.limit(1).all() %}
          <img src="{{ logo.getUrl() }}" />
      {% endfor %}
  {% endfor %}
  
  ```
  
  If your API isn't brought in with Feed Me (or akin) and you can't change the home/away fields to entry selectable fields, you can select a team by matching its ID field to the given ID field like so:
  
  ```
  {% set awayId = fixture.awayTeamId %}
  {% set awayTeam = craft.entries.section('clubs').search('clubId:'~awayId).limit(1) %}
    {% for team in awayTeam %}
      ...
  
  ```
  
  > **Comments:**
  > **username_0**: A perfect solution! Thank you so much Indigo - this works a treat.  
  
  ---
  
  