CMS Development

oliviadurr
Participant | Platinum Partner
Participant | Platinum Partner

Pulling Related Rows in HubDB on a Dynamic Page

SOLVE

Hi--

 

I am working on editing a part of a custom module for a dynamic page using HubDB. The part I am struggling the most with is creating a "Related Projects" area that should pull content from other rows in the same DB table that has the same tags in one column.

 

This is the code block that I'm currently using:

{% if showRelatedProjects %}
   <div class="{{ module_name }}__related-projects">
      <h3>Related Projects</h3>
      {% set count = module.related_projects_count %}
      {% set allHubDBRows = hubdb_table_rows(dynamic_page_hubdb_table_id) %}
      {% for capability in capabilities %}
         {% set relatedProjectsQuery = '&limit='~count~'&'~'capability__contains='~capability.name|lower|replace(' ','%20')|replace('&','%26')~'&hs_path__not_like='~path~'&exp_disable=false' %}
         {% set resources = hubdb_table_rows(allHubDBRows,relatedProjectsQuery)|rejectattr('disable_project') %}
         {% for item in capability %}
            {{ project_card(module_name,item) }}
         {% endfor %}
      {% endfor %}
      <a class="cta-link" href="{{ content.absolute_url|replace(dynamic_page_hubdb_row.hs_path,'') }}">
         <span class="icon">{{ icon('gallery') }}</span>
         <span>View All Projects</span>
      </a>
   </div>
{% endif %}

 

This is what renders on the page:

oliviadurr_0-1639765987165.png

It's pulling the correct module 3 times (one for each tag/capability), however, it's populating only with the content of the current dynamic page. How would I go about so it only shows 2 of the module total and uses information from other rows?

0 Upvotes
1 Accepted solution
oliviadurr
Solution
Participant | Platinum Partner
Participant | Platinum Partner

Pulling Related Rows in HubDB on a Dynamic Page

SOLVE

Hi--

 

I actually realized my mistake for this. This is the new code block:

 

{% if showRelatedProjects %}
		<div class="{{ module_name }}__related-projects">
				<h3>Related Projects</h3>
				{% set count = module.related_projects_count %}
				{% for capability in capabilities %}
						{% if loop.first %}
								{% set relatedProjectsQuery = '&limit='~count~'&capability__contains='~capability.name|replace(' ','%20')|replace('&','%26')~'&hs_path__not_like='~path~'&exp_disable=false' %}
				{% set query = '&market__contains='~market.name|replace(' ','%20')|replace('&','%26') %}
								{% set relatedProjects = hubdb_table_rows(dynamic_page_hubdb_table_id, relatedProjectsQuery) %}
								{% for item in relatedProjects %}
									{{ project_card(module_name,item) }}
								{% endfor %}
						{% endif %}
				{% endfor %}
				<a class="cta-link" href="{{ content.absolute_url|replace(dynamic_page_hubdb_row.hs_path,'') }}">
				<span class="icon">{{ icon('gallery') }}</span>
				<span>View All Projects</span>
				</a>
		</div>
{% endif %}

View solution in original post

3 Replies 3
dennisedson
HubSpot Product Team
HubSpot Product Team

Pulling Related Rows in HubDB on a Dynamic Page

SOLVE

Well @oliviadurr , I guess I will turn this around and see if you can help @JLamb14 over here  😆

0 Upvotes
oliviadurr
Solution
Participant | Platinum Partner
Participant | Platinum Partner

Pulling Related Rows in HubDB on a Dynamic Page

SOLVE

Hi--

 

I actually realized my mistake for this. This is the new code block:

 

{% if showRelatedProjects %}
		<div class="{{ module_name }}__related-projects">
				<h3>Related Projects</h3>
				{% set count = module.related_projects_count %}
				{% for capability in capabilities %}
						{% if loop.first %}
								{% set relatedProjectsQuery = '&limit='~count~'&capability__contains='~capability.name|replace(' ','%20')|replace('&','%26')~'&hs_path__not_like='~path~'&exp_disable=false' %}
				{% set query = '&market__contains='~market.name|replace(' ','%20')|replace('&','%26') %}
								{% set relatedProjects = hubdb_table_rows(dynamic_page_hubdb_table_id, relatedProjectsQuery) %}
								{% for item in relatedProjects %}
									{{ project_card(module_name,item) }}
								{% endfor %}
						{% endif %}
				{% endfor %}
				<a class="cta-link" href="{{ content.absolute_url|replace(dynamic_page_hubdb_row.hs_path,'') }}">
				<span class="icon">{{ icon('gallery') }}</span>
				<span>View All Projects</span>
				</a>
		</div>
{% endif %}
dennisedson
HubSpot Product Team
HubSpot Product Team

Pulling Related Rows in HubDB on a Dynamic Page

SOLVE

@JLamb14 👋

While you are working on your  other hubdb project, maybe you could help here? 😀

0 Upvotes