How to add dynamic content to my HS page ?

Top Contributor

Hi,
I am trying to add Some dynamic contents in HS template, I need to show different company details on Company Listing page and when clicking readmore it need to redirect to single company page with single company details.
I have done it using HubDB by passing the table id through URL like
<a href="/directorylpsingle/?company={{row.hs_id}}" >read more</a>
and by getting the value on the single page by

{% set table = request.query_dict.get('company') %}
{% set rows = hubdb_table_rows(350294,table ) %}
{% for row in rows %}
{% set hid = row.hs_id %}
{% if hid == table %}
<div><h1>{{ row.company_name }}</h1></div>
{% if row.company_image %}
<img src="{{ row.company_image.url }}" alt="{{row.company_name }}">
{% endif %}

When i used

{% set row = hubdb_table_row(<tableId>, <rowId>) %}
i got the error as "TemplateSyntaxException : Error invoking function hubdb_table_row'' ",

so i used
{% set rows = hubdb_table_rows(350294,table ) %}

then it shown the complete row by looping its worked fine.

My questions are
1. Is this metod that i am following is correct ?
2. when redirecting to the single page is showing an id on URL ( /?id=23423 ). is there any methods in hubl to change Permalink
3. Why i got error on single page when tried to
4. Is there any simpler method than this on HS using Hubl.

1 Reply 1
Highlighted
HubSpot Product Team

Hi Subin,

 

Since your query string has the id in the form "id=23423", I think in your case what you can do:

{% set company_id = request.query_dict.get('id') %}
{% set row = hubdb_table_row(350294, company_id) %}

 

{% set rows = hubdb_table_rows(350294,table ) %} is getting all the rows back which is pretty inefficient.

 

For this code:

{% set table = request.query_dict.get('company') %}
{% set rows = hubdb_table_rows(350294,table ) %}

hubdb_table_rows does not accept an id as the second argument. It's probably ignoring the argument and then just sending back all the rows. If you just want to get all the rows, you can omit the second argument. 

 

See http://designers.hubspot.com/docs/tools/hubdb for more of the differences between the two functions.

 

I hope that helps.