This is the current code that allows me to pull through the name and id. So I know that the table connects up and is pulled data.
{% set column = module.landing_pages.columns %}
{% set title = column.landing_page_title %}
{% set lp = hubdb_table_row(module.landing_pages.table_id, module.landing_pages.id) %}
{% if title %}<h2>{{ title }}</h2>{% endif %}
{% if lp.overview_items %}
<ul class="overview-list">
{# Loop through each related row from the foreign table. #}
{% for foreignTable in lp.overview_items %}
<li>
{# 'hs_id' and 'name' are standard HubDB row properties. #}
{{ foreignTable.hs_id }} — {{ foreignTable.name }} — {{ foreignTable.image.url }} — {{ foreignTable.test }}
</li>
{% endfor %}
</ul>
{% endif %}
{% if module.lp_select.columns.overview_items != null %}
<div class="cards__wrapper">
<div class="content-wrapper">
<div class="cards cards--{{ module.style.cards_per_row }}">
{% for item in module.lp_select.columns.overview_items %}
<div class="card__details overview">
<h3 class="card__title">
{{item.name}}
</h3>
<p>
{{item.id}}
</p>
<img src="{{item.image.src }}" alt="{{item.test}}">
</div>
{% endfor %}
</div>
</div>
</div>
{% endif %}
<div>
<div class="content-wrapper">
{{ module.lp_select.columns.overview }}
</div>
</div>
I’m not sure what I am doing wrong or what I need to change in order to see the images column data or the test column data. Thanks in advance for any help.
I wanted to share a couple of HubSpot dev docs that should help explain what you’re seeing with HubDB Foreign ID
Additionally, I’m tagging a few community experts who may be able to share further insights. Hey there, @HFisher7, @Indra, and @BarryGrennan, any ideas here?
@Woodsy - you posting here leaves several questions in my mind. I’ve worked with HubDB extensively and perhaps have a bit of a conventional way to use it. But I’ve also tripped over several quirks.
The first question in my mind is whether the data in the table you are referencing has been published (rather then being in draft mode). This is an easy mistake to make during development.
The second question comes from your code, which seems to retrieve only a single HubDB row, but then seems to loop over an expected set of rows.
And the third question is about terminology. The reference to ‘foreign table’ is very specific in HubDB, implying a link from one table to another. You don’t mention any such table to table relationship, so I’m reading too much into you description. But if you do have such a setup, to extract data from the foreign table, you woudl have to read its rows explicity, after you find ithe table id.
I have been looking to search the whole of the parent DB. I actually don’t need the code to look through all the parents database to pull rows, I only need a single row that has been selected by the content creator.
I have create a HubDB row select field in a custom module that allows the user to select a row from the parent DB:
This then pulls a page title and also looks in a column called ‘overview_items’. This column is pulling data from a foreign DB. This column is a multi select so I can which services apply to each row item.
I have written code that loops through the parent DB and pulls the two rows and shows the selected foreign DB content.
{% set table = hubdb_table_rows('136413078') %}
{# Loop through each row of the table #}
{% for row in table %}
<h2>{{ row.landing_page_title }}</h2>
{# Loop through each info in Foreign ID column #}
{% for info in row.overview_items %}
<h3>{{ info.name }}</h3>
{{ info.description }}
<img src="{{info.image.url }}" style="width: 100px; height:100px;" alt="{{info.description}}">
{% endfor %}
{% endfor %}
Rather than the parent DB being looked up and looped I would like to be able to select a single row from the Parent DB using the HubDB row select field.
First I would need to change this line from a general table lookup to a row select field control
{% set table = hubdb_table_rows('136413078') %}
Then I need to change the main part of the code to just pull the info from the selected row 'overview_items column.
Hi, I think the earlier posts answers might be more complex than what is needed.
I don’t need the code to look through all the parents database to pull rows.
I have create a HubDB row select field in a custom module that allows the user to select a row from the parent DB:
This then pulls a page title and also looks in a column called ‘overview_items’. This column is pulling data from a foreign DB. This column is a multi select so I can which services apply to each row item.
I have written code that loops through the parent DB and pulls the two rows and shows the selected foreign DB content.
{% set table = hubdb_table_rows('136413078') %}
{# Loop through each row of the table #}
{% for row in table %}
<h2>{{ row.landing_page_title }}</h2>
{# Loop through each info in Foreign ID column #}
{% for info in row.overview_items %}
<h3>{{ info.name }}</h3>
{{ info.description }}
<img src="{{info.image.url }}" style="width: 100px; height:100px;" alt="{{info.description}}">
{% endfor %}
{% endfor %}
Rather than the parent DB being looked up and looped I would like to be able to select a single row from the Parent DB using the HubDB row select field.
First I would need to change this line from a general table lookup to a row select field control
{% set table = hubdb_table_rows('136413078') %}
Then I need to change the main part of the code to just pull the info from the selected row 'overview_items column.
Hello @Woodsy,
You can give it a shot:
{% set main_table_id = “1234567(example)” %} {# The table you are currently looping through #}
{% set foreign_table_id = “7654321(example)” %} {# The table containing the Overview Items #}
{% set foreign_rows = hubdb_table_rows(foreign_table_id) %}
{% set foreign_map = {} %}
{% for f_row in foreign_rows %}
{% do foreign_map.update({f_row.hs_id|string : f_row}) %}
{% endfor %}
{# Fetch your primary data #}
{% set rows = hubdb_table_rows(main_table_id) %}
{% for row in rows %}
<div class=“main-card”>
<h2>{{ row.name }}</h2>
<div class=“overview-items-grid”>
{% for item_pointer in row.overview_items %}
{% set full_item = foreign_map[item_pointer.id|string] %}
{% if full_item %}
<div class=“item-detail”>
<h3>{{ full_item.name }}</h3>
<p>{{ full_item.description }}</p>
{% if full_item.image.url %}
<img src=“{{ full_item.image.url }}” alt=“{{ full_item.image.alt }}”>
{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}