# Foreign IDs in multilevel dynamic page template populating all rows

**URL:** <https://community.hubspot.com/t/foreign-ids-in-multilevel-dynamic-page-template-populating-all-rows/60654>\
**Category:** CMS Development\
**Tags:** hubdb\
**Created:** [July 11, 2022, 4:56am UTC](https://community.hubspot.com/t/foreign-ids-in-multilevel-dynamic-page-template-populating-all-rows/60654 "2022-07-11T04:56:27Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![dannio](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dannio/32/95715_2.png) [@dannio](https://community.hubspot.com/u/dannio)\
**Post date:** [July 12, 2022, 6:15am UTC](https://community.hubspot.com/t/foreign-ids-in-multilevel-dynamic-page-template-populating-all-rows/60654/5 "2022-07-12T06:15:08Z")

</div>

@NWonders which level is which in your logic?

Just had a quick read of [this](https://developers.hubspot.com/docs/cms/guides/dynamic-pages/hubdb/multilevel) and it seems for multi level pages, you should be using the **hs\_child\_table\_id** variable to get the child table values of your row:

```lia-code-sample
{% if dynamic_page_route_level == 0 %}
	<h1>Categories</h1>
 {% set rows = hubdb_table_rows(dynamic_page_hubdb_table_id) %}
 {% for row in rows %}
 	<h2><a href="{{ request.path }}/{{ row.hs_path }}">{{ row.hs_name }}</a></h2>
 	{% set childRows = hubdb_table_rows(row.hs_child_table_id) %}
 	{% for childRow in childRows %}
 	<li><a href="{{ request.path }}/{{ row.hs_path }}/{{childRow.hs_path}}">{{ childRow.hs_name }}</a></li> 
 	{% endfor %} 
 {% endfor %}
{% endif %}

```

I gave it a try and it seems to work fine.

Remember that child pages aren’t generated via foreign ID columns.

Level 0 is the main page (one where you select the hubdb for the page)

Level 1 is the first hubdb level

Level 2 s the child table of level 1

Everything in each child level are items belonging to the parent level, i.e every item in level 2 is a subpage of level 1.

I’ve tried this on my end:

```lia-code-sample
{% if dynamic_page_route_level == 0 %}
{% set rows = hubdb_table_rows(dynamic_page_hubdb_table_id) %}
<ul>
 {% for row in rows %}
 {% set childRows = hubdb_table_rows(row.hs_child_table_id) %}
 {% for childRow in childRows %}
 <li><a href="{{ request.path }}/{{ row.hs_path }}/{{childRow.hs_path}}">{{ childRow.name }}</a></li> 
 {% endfor %} 
 {% endfor %}
</ul>
{% elif dynamic_page_route_level == 1 %}
{{ dynamic_page_hubdb_row.level_1_items}}
{% elif dynamic_page_route_level == 2 %}
{{ dynamic_page_hubdb_row.level_2_items}}
{% endif %}

```

and everything shows up as intended. (level\_1\_items and level\_2\_items are the foreign columns I added)

Or am I misunderstanding your logic?

---

_[View the full topic](https://community.hubspot.com/t/foreign-ids-in-multilevel-dynamic-page-template-populating-all-rows/60654)._
