<p>Each of my entries has a table with budget projections.</p>

<p>I loop through related entries.   <strong>But, how can I loop through and bring in the related table?</strong></p>

<p>This is my table for the entry:</p>

<pre><code> {% set field = craft.app.fields.getFieldByHandle('budgetProjections') %}
    &lt;table width="100%"&gt;
        &lt;tr&gt;

            {% for column in field.settings.columns %}
                &lt;th&gt;{{ column.heading }}&lt;/th&gt;
            {% endfor %}

        &lt;/tr&gt;
        {% for row in entry.budgetProjections %}
        &lt;tr&gt;    
            &lt;td&gt;{{ row.col1 }}&lt;/td&gt;
            &lt;td&gt;{{ row.col2 }}&lt;/td&gt;
            &lt;td&gt;{{ row.col3 }}&lt;/td&gt;
            &lt;td&gt;{{ row.col4 | number_format (0,'.',',')}}&lt;/td&gt;
            &lt;td&gt;{{ row.col5 | number_format (0,'.',',')}}&lt;/td&gt;
            &lt;td&gt;{{ row.col6 | number_format (0,'.',',')}}&lt;/td&gt;
            &lt;td&gt;{{ row.col7 | number_format (0,'.',',')}}&lt;/td&gt;
            &lt;td&gt;{{ row.col8 | number_format (0,'.',',')}}&lt;/td&gt;
            &lt;td&gt;{{ row.col9 | number_format (0,'.',',')}}&lt;/td&gt;
            &lt;td&gt;{{ row.col10 | number_format (0,'.',',') }}&lt;/td&gt;
        &lt;/tr&gt;          
        {% endfor %}
    &lt;/table&gt;
</code></pre>

<p>This is my loop for related entries.  It creates a button and link for each related entry.  <strong>But now, I want to pull in the related table.  How do I do that?</strong></p>

<pre><code>{% set related = entry.relatedBudgetItems.all() %}
    {% if related %}

    &lt;p&gt; {% for item in related %}

        &lt;a href="{{ item.getUrl() }}" class="button primary radius"&gt;&lt;i&gt;{{ item.title}} ({{ item.lineItem }})-  &lt;/i&gt;&lt;/a&gt;
        {% endfor %}
    &lt;/p&gt;   
    {% endif %}
</code></pre>

<p>Thanks!</p>

CC BY-SA 4.0
2018-05-04T19:11:38.527Z
Can't you do it the same way as above just with the `item` variable instead of the `entry`
Robin Schambach
CC BY-SA 4.0
2018-05-04T19:26:55.007Z
@RobinSchambach  Yep.  I forgot all about that `entry`.  Thanks.
Hellyar
CC BY-SA 4.0
2018-05-04T19:41:11.550Z
If your question is solved, would you mind answering it with your solution?
Robin Schambach
<templating><relatedto>
How can I pull in a related table?
# How can I pull in a related table?

(Asked by: username_0 on 2018-05-04)

Each of my entries has a table with budget projections.
I loop through related entries.   But, how can I loop through and bring in the related table?
This is my table for the entry:
 {% set field = craft.app.fields.getFieldByHandle('budgetProjections') %}
    
        

            {% for column in field.settings.columns %}
                {{ column.heading }}
            {% endfor %}

        
        {% for row in entry.budgetProjections %}
            
            {{ row.col1 }}
            {{ row.col2 }}
            {{ row.col3 }}
            {{ row.col4 | number_format (0,'.',',')}}
            {{ row.col5 | number_format (0,'.',',')}}
            {{ row.col6 | number_format (0,'.',',')}}
            {{ row.col7 | number_format (0,'.',',')}}
            {{ row.col8 | number_format (0,'.',',')}}
            {{ row.col9 | number_format (0,'.',',')}}
            {{ row.col10 | number_format (0,'.',',') }}
                  
        {% endfor %}
    

This is my loop for related entries.  It creates a button and link for each related entry.  But now, I want to pull in the related table.  How do I do that?
{% set related = entry.relatedBudgetItems.all() %}
    {% if related %}

     {% for item in related %}

        {{ item.title}} ({{ item.lineItem }})-  
        {% endfor %}
       
    {% endif %}

Thanks!

**Tags:** templating, relatedto

> **Comments:**
> **username_1**: Can't you do it the same way as above just with the `item` variable instead of the `entry`  
> **username_0**: @RobinSchambach  Yep.  I forgot all about that `entry`.  Thanks.  
> **username_1**: If your question is solved, would you mind answering it with your solution?  

---

## 0 answers

