HubDB row show output in module

Seasons greetings! :christmas_tree:

I’m a marketer trying to code without much knowledge/skills but getting there with the help of hubspot support and this great community!

At the moment I’m trying to create/alter a custom module so that I can pull in info from HubDB Tables. Was amazed when I found out this was built into the module builder as hubdbrow_field.

Working in Higher Education and my aim is to display course information in a little box for quick reference e.g. course code, duration, locations, etc. I feel like I’m close to a solution but probably doing something dumb so it doesn’t work. Read a lot of the documentation but I’m pretty bad at understanding so just having a crack.

Have started with:

<div>
{{ module.hubdbrow_field }}
<p>Delivery Locations:{% for course_delivery_locations in module.hubdbrow_field %} {{ course_delivery_locations.name }} {% endfor %}</p>
</div>

And the settings on the sidebar thing are:

which is displaying as:

So I just want to use the highlighted part and have it display as:

Delivery Locations: Sydney, Melbourne, Brisbane, etc.

Any advice is appreciated. Thanks in advance for your help.

Hi @Luke-Simp ,

You’re not far from getting your code displaying what you need! Your problem is that course_delivery_locations is referecing values from a joined table. As you can add multiple location the values are stored in an array. You need to loop thrue the array to get the name of every location sets.

Can you try the following code?

<div>
 {{ module.hubdbrow_field }}
 <p>Delivery Locations:
 {% for course_delivery_locations in module.hubdbrow_field -%}
 {% for location in course_delivery_locations -%}
 {{ location.name }}{{ ', ' if not loop.last }}
 {%- endfor %}
 {%- endfor %}
 </p>
</div>

Bests,

Matthieu

matthieu.berard@markentive.com

Thanks for such a quick reply :blush:
The output I’m now getting is now:
Delivery Locations: , , ,
This seems to be a bit closer to what I’m after but should be 7 locations whereas looks like the commas are only indicating four which is strange.
Extra info: the table being referenced is “campus” and the name of the locations is “name”
So I also tried:

{{ module.hubdbrow_field }}

Delivery Locations: {% for course_delivery_locations in module.hubdbrow_field -%} {% for campus in course_delivery_locations -%} {{ campus.name }}{{ ', ’ if not loop.last }} {%- endfor %} {%- endfor %}

But this had the same result.

I think I answered you too quickly and I forgot something… My bad! I updated your last piece of code can you try it?

Delivery Locations: {% for row in module.hubdbrow_field -%} {% for campus in row.course_delivery_locations -%} {{ campus.name }}{{ ', ' if not loop.last }} {%- endfor %} {%- endfor %}

Thanks for the update.
“Delivery Locations:” this is now the output I’m getting.

If my answer fulfill your needs you can marked it as a solution :blush:

Thanks!

Sorry Matthieu, actually meant “Delivery Locations:” is what is showing without anything data coming from the table. I feel like its so close though.

Code is:

<div>
 <p>Delivery Locations: {% for row in module.hubdbrow_field -%} 
 {% for campus in row.course_delivery_locations -%} {{ campus.name }}
 {{ ', ' if not loop.last }} {%- endfor %} {%- endfor %}
 </p>
</div> 

Thanks for the help so far!

Again, my bad… if think it’s not my day today :sweat_smile:
I need to create some tests to reproduce your use case, I’ll get back to you once I have the right answer!

@Luke-Simp I think I find the solution for your problem. Sadly {{ module.hubdbrow_field }} won’t return value of joined table… My workaround was to get the data of the row form the hubdb_table_rows function. By doing that HubSpot return the values from the joined table. Here is my code:

<p>Delivery Locations:
{% for row in module.hubdbrow_field %}
 {%- set row_id = row.id -%}
 {%- set table_id = row.table_id -%}	
 {% for row in hubdb_table_rows(table_id, "&hs_id="~row_id) -%}
	{% for campus in row. course_delivery_locations -%}
	 {{ campus.name }}{{ ', ' if not loop.last }}
	{%- endfor %}
 {%- endfor %}
{%- endfor %}
</p>

Hope that this time it will work! :crossed_fingers:

Amazing! You’re a legend. Thanks for your help :slightly_smiling_face:

Hi Matthieu/anyone else who’s interested.

I’m having some trouble again. Getting an error where I’m getting the below message and now none of the data is displaying. I don’t know if it’s me or what has happened to change it.

Any thoughts? Thanks in advance :slightly_smiling_face:

Hi @Luke-Simp, that’s unfortunate… Does the row that you are referencing still exists? Can you try with a different row?

Matthieu