CMS Development

Xzito
Member | Gold Partner
Member | Gold Partner

Printing Values from HubDB "Multi-Select" column

SOLVE

Hi, 

I'm currently building a custom module using hubDB and would like to know if is possible to show the printing value of a "Multi-select" column that I created. Right now when I render the code I get the follow:

 

[{id=5, name='Option 1', order=0}, {id=7, name='Option 3', order=2}]
 
But I would like to get the just the "name" printing value:

Option 1 Option 3
 
This is the code I created. i would really appreciate any help.
 
<div>
{% set gallery = hubdb_table_rows('1111111') %}
{% for scimg in gallery %}
<div class="options">
<p class="display-options">{{ scimg.project_type }}</p>
</div>
{% endfor %}
</div>
0 Upvotes
1 Accepted solution
lscanlan
Solution
HubSpot Employee
HubSpot Employee

Printing Values from HubDB "Multi-Select" column

SOLVE

Hi @Xzito,

 

So a multi select column field will return a list of dictionaries where each selection is its own dictionary. So just like you're looping through the table rows, you'll also need to loop through the dictionaries in that list. Once inside our nested loop, we can access the keys from those dictionaries. So in your case, that might look something like this:

 

{% set gallery = hubdb_table_rows('1111111') %}
{% for scimg in gallery %}
  <div class="options">
    {% for item in scimg.project_type %}
      <p class="display-options">{{ item.name }}</p>
    {% endfor %}
  </div>
{% endfor %}

And that will print what you're looking for. Let me know if you have any questions about it.

 

- Leland

Leland Scanlan

HubSpot Developer Support

View solution in original post

2 Replies 2
lscanlan
Solution
HubSpot Employee
HubSpot Employee

Printing Values from HubDB "Multi-Select" column

SOLVE

Hi @Xzito,

 

So a multi select column field will return a list of dictionaries where each selection is its own dictionary. So just like you're looping through the table rows, you'll also need to loop through the dictionaries in that list. Once inside our nested loop, we can access the keys from those dictionaries. So in your case, that might look something like this:

 

{% set gallery = hubdb_table_rows('1111111') %}
{% for scimg in gallery %}
  <div class="options">
    {% for item in scimg.project_type %}
      <p class="display-options">{{ item.name }}</p>
    {% endfor %}
  </div>
{% endfor %}

And that will print what you're looking for. Let me know if you have any questions about it.

 

- Leland

Leland Scanlan

HubSpot Developer Support
Xzito
Member | Gold Partner
Member | Gold Partner

Printing Values from HubDB "Multi-Select" column

SOLVE

Hi Leland, 

 

Thank you so much for your help. That was the anwser I was looking for!!

0 Upvotes