CMS Development

Philip_Marsh
Contributor

Displaying recent entries from chlid HubDB

SOLVE

Hi,

I have a parent database, that has 3/4 child DB's sitting underneath it. What I need is the page to pull in the 5 most recent entries and display them in a list. 

 

I'm using the following code, but it doesn't appear to be working.

 

The code is meant to create an array, pulling in all entries across the child DBs, sort by date created, and then loop through 5 times and spit out the 5 latest entries. 

 

What am I missing?

 

			{% set childCombineArr = [] %}
			{% for row in hubdb_table_rows(dynamic_page_hubdb_table_id, queryparam) %}
			{% if row.hs_child_table_id %}
				{% set child_table = hubdb_table_rows(row.hs_child_table_id) %}
				{% for row in child_table %}
					{% set timeAdded = row.createdAt %}
					{% do childCombineArr.append({'timeAdded': timeAdded, 'row': row}) %}
				{% endfor %}
			{% endif %}
		{% endfor %}
		{% for item in childCombineArr|sort(True, False, 'timeAdded') %}
			{% if loop.index <= 5 %}
				{% set row = item.row %}
				{{row.name}}
			{% endif %}
		{% endfor %}

 

0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

Displaying recent entries from chlid HubDB

SOLVE

@dennisedson I'm pretty sure this is based off my code which I've provided on the forum before haha.

 

@Philip_Marsh You want row.hs_created_at not row.createdAt so 

{% set timeAdded = row.hs_created_at %}

View solution in original post

4 Replies 4
dennisedson
HubSpot Product Team
HubSpot Product Team

Displaying recent entries from chlid HubDB

SOLVE

@piersg , @amwilie -- see anything funky here?

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show
0 Upvotes
piersg
Solution
Key Advisor

Displaying recent entries from chlid HubDB

SOLVE

@dennisedson I'm pretty sure this is based off my code which I've provided on the forum before haha.

 

@Philip_Marsh You want row.hs_created_at not row.createdAt so 

{% set timeAdded = row.hs_created_at %}
Philip_Marsh
Contributor

Displaying recent entries from chlid HubDB

SOLVE

I just checked and yes it is your code. Thank you for supplying it originally. 

 

Thank you! That's fixed the issue. Now I just need to style it accordingly.

dennisedson
HubSpot Product Team
HubSpot Product Team

Displaying recent entries from chlid HubDB

SOLVE

@piersg  we need a code collection area for the Community 👀

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show