An area, I'm not sure on is recent additions to the DB. What I'm looking to do is create a portion of the page that displays the last 5 additions to any of the HubDB's.
Using that tutorial, you can just loop through all of the Childs DB's and have the page populate with all the products. It's then fairly straight forward to restrict it to only display 5/6 entries. What I'm not sure on is how to only display the last 5 products added to any of the DB's. If this was using a single DB, that's fairly straight forward but I'm not sure how you would accomplish this across multiple Child DB's.
Multilevel dynamic pages with HubDB - Recent products
resolver
Yep, exactly 👍
{% do childCombineArr.append({'date': date, 'row': row}) %} is the line that adds the child db row info to the array. 'row' is just all the info in each row, and will be an object itself, but the info you want to sort (in my case date) by has to be added outside of the row object, as it were, to be used by the sort function on childCombineArr. So it returns
For you because you want to sort by the latest 5 products added you could use createdAt instead of date and then use if loop.index is less than or equal to 5 e.g.
{% set childCombineArr = [] %}
{% for row in table %}
{% 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}}
{% endif %}
{% endfor %}
dez 17, 20204:23 AM - editado dez 17, 20204:24 AM
Conselheiro(a) de destaque
Multilevel dynamic pages with HubDB - Recent products
resolver
Hi @Philip_Marsh (thanks @tjoyce). Something I did to sort multiple child DBs by date could be useful for you. Basically combine them into a single array then sort that resulting array.
{% set childCombineArr = [] %}
{% for row in table %}
{% if row.hs_child_table_id %}
{% set child_table = hubdb_table_rows(row.hs_child_table_id) %}
{% for row in child_table %}
{% set date = row.start_datetime %}
{% do childCombineArr.append({'date': date, 'row': row}) %}
{% endfor %}
{% endif %}
{% endfor %}
{% for item in childCombineArr|sort(True, False, 'date') %}
{% set row = item.row %} // allows you to use standard row.title as if it were for "row in table" instead of item.row.title
{{row.title}}
{{row.start_datetime|datetimeformat('%e %B %Y')}}
//...etc
{% endfor %}
Multilevel dynamic pages with HubDB - Recent products
resolver
Yep, exactly 👍
{% do childCombineArr.append({'date': date, 'row': row}) %} is the line that adds the child db row info to the array. 'row' is just all the info in each row, and will be an object itself, but the info you want to sort (in my case date) by has to be added outside of the row object, as it were, to be used by the sort function on childCombineArr. So it returns
For you because you want to sort by the latest 5 products added you could use createdAt instead of date and then use if loop.index is less than or equal to 5 e.g.
{% set childCombineArr = [] %}
{% for row in table %}
{% 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}}
{% endif %}
{% endfor %}