CMS Development

TSwisher008
Participant

Multi Resource hubDB Table

SOLVE

I have a hubDB database to build dynamic pages with multiple resources (analyst reports, whitepapers etc. I have a single select column "resource_type.  

I've noticed that if I take the end slug from the resource and put it on the end of the example.com/resource/whitepaper/my-slug or /resource/analyst-report/my-slug, it will render regardless because they are in the same database. 

So I have added code to ID what resource it is, but now I end up with a blank page when it isn't the correct resource. Nav and footer, but no body. I've tried to do an else and force a 404, but have had no luck. 

Can someone give me some help on what the best practice would be in this situation? The code (screenshot) gives me a blank page. If I add ?hsCacheBuster=1234, it shows the 404, but I think that is because it is refreshing the page. It has been 24 hours, so I don't think it is a caching issue.

Thanks in advance.

Screenshot 2025-06-24 at 12.30.10 PM.png

 



 

1 Accepted solution
GRajput
Solution
Recognized Expert | Gold Partner
Recognized Expert | Gold Partner

Multi Resource hubDB Table

SOLVE

Hi @TSwisher008 

 

The main problem lies in the logic where it is finding an exact page match for the slug.
i.e. dynamic_page_hubdb_row exists, but the problem is that it doesn't match that template that it is built for, like here, it is for "whitepaper", and the slug is for "analyst-reports". This is why the condition fails and skips everything except nav and footer. If the dynamic_page_hubdb_row exists but is not the same type, it also won't give a 404. What you have to do is explicitly return a 404 page when resource_type.name is not matched.

 

{% if dynamic_page_hubdb_row %}
  {% if dynamic_page_hubdb_row.resource_type.name == 'whitepapers' %}
    <!-- Render the whitepapers content -->
    <div class="whitepapers-main-cont container">
      <!-- existing hero, etc. -->
    </div>
  {% else %}
    {{ set_response_code(404) }}
    <div class="error-container">
      <h1>404 - Not Found</h1>
      <p>The resource you are looking for does not exist or is of the wrong type.</p>
    </div>
  {% endif %}
{% elif dynamic_page_hubdb_table_id %}
  <!-- Index listing page -->
  <div class="resources-hero resource-hero-bg">...</div>
  <div class="resource-main-container container">
    <!-- listing logic -->
  </div>
{% else %}
  {{ set_response_code(404) }}
  <div class="error-container">
    <h1>404 - Not Found</h1>
  </div>
{% endif %}

 

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.

Thanks!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


View solution in original post

3 Replies 3
GRajput
Solution
Recognized Expert | Gold Partner
Recognized Expert | Gold Partner

Multi Resource hubDB Table

SOLVE

Hi @TSwisher008 

 

The main problem lies in the logic where it is finding an exact page match for the slug.
i.e. dynamic_page_hubdb_row exists, but the problem is that it doesn't match that template that it is built for, like here, it is for "whitepaper", and the slug is for "analyst-reports". This is why the condition fails and skips everything except nav and footer. If the dynamic_page_hubdb_row exists but is not the same type, it also won't give a 404. What you have to do is explicitly return a 404 page when resource_type.name is not matched.

 

{% if dynamic_page_hubdb_row %}
  {% if dynamic_page_hubdb_row.resource_type.name == 'whitepapers' %}
    <!-- Render the whitepapers content -->
    <div class="whitepapers-main-cont container">
      <!-- existing hero, etc. -->
    </div>
  {% else %}
    {{ set_response_code(404) }}
    <div class="error-container">
      <h1>404 - Not Found</h1>
      <p>The resource you are looking for does not exist or is of the wrong type.</p>
    </div>
  {% endif %}
{% elif dynamic_page_hubdb_table_id %}
  <!-- Index listing page -->
  <div class="resources-hero resource-hero-bg">...</div>
  <div class="resource-main-container container">
    <!-- listing logic -->
  </div>
{% else %}
  {{ set_response_code(404) }}
  <div class="error-container">
    <h1>404 - Not Found</h1>
  </div>
{% endif %}

 

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.

Thanks!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


TSwisher008
Participant

Multi Resource hubDB Table

SOLVE

Thank you for the reply. One of the big issues for me was 

{{ set_response_code(404) }}

never updated the response header. It was still giving out a 200.

0 Upvotes
Victor_Becerra
Community Manager
Community Manager

Multi Resource hubDB Table

SOLVE

Hey @TSwisher008,

Thanks for reaching out with this! This is a common challenge when setting up dynamic pages with HubDB, especially when dealing with different resource types from a single table. Hitting that blank page is definitely frustrating.

I'm tagging a few community members who can help with this:
@kosalaindrasiri @SteveHTM @GiantFocal 
Hopefully, they can provide some insights to help you sort this out!

Victor Becerra
Community Marketing Manager

Did my post help answer your question? Mark this as a solution.

0 Upvotes