Printing Multi-selector names

Hi,

I have a problem with printing from a multi-selector. I know this seems to be a common problem and I have tried multiple solutions but all produce the same result.

I have set up in HubDB a column called Location Selector. All I want to do is print the values(Name) of each selection.

When I try…

<ul class=“list-con”>
<li class=“icon1”>Location: {{ dynamic_page_hubdb_row.location_selector }}</li>
<li class=“icon2”>Employment: {{ dynamic_page_hubdb_row.employment }}</li>
</ul>

I get…

[{id=1, name=‘Cheadle’, order=0}, {id=2, name=‘Manchester’, order=1}]

As per other posts, I just want to post the name. If I use {{ dynamic_page_hubdb_row.location_selector.name }} I get nothing. It’s blank.

I even tried the below, which works, but prints out the full value as shown above.

{% set table = hubdb_table_rows(tableID, queryparam) %}
{% for row in table %}
<ul class=“list-con”>
<li class=“icon1”>Location: {{ row[“location_selector”] }}</li>
<li class=“icon2”>Employment: {{ dynamic_page_hubdb_row.employment }}</li>
</ul>
{% endfor %}

However, if I use row[“location_selector”] .name I get the following warning. I don’t get how it cannot resolve a property when it clearly shows name as a property.

Warning:15:0 Cannot resolve property ‘name’ in ‘[{id=1, name=‘Cheadle’, order=0}, {id=2, name=‘Manchester’, order=1}]’

what am I missing?

Additional:

I can get .name to work if in Hubdb table I use a select, and not a multi-select.

What the solution if I need it to be done using a multi-select

Hi @pm8rsh88,

A multi select field is stored as a list. So just like you need to loop through the rows of a HubDB table (or at least if you’re not using a dynamic page), you’ll also need to loop through the list items of a multi select field. And each selection is a dictionary. So if you’re trying to print the names of each selection, you’d want to loop through the list and then access the name attribute within each loop. A simple version of that might look like:

{% for item in dynamic_page_hubdb_row.location_selector %}
 {{ item.name }}
{% endfor %}

In your case, I think you’re more looking for something like this (I’ve also added code to make the names comma-separated):

<ul class="list-con">
 <li class="icon1">Location: {% for item in dynamic_page_hubdb_row.location_selector %}{{ item.name }}{% if not loop.last %},{% endif %} {% endfor %}</li>
 <li class="icon2">Employment: {{ dynamic_page_hubdb_row.employment }}</li>
</ul>

Does that help? If I can clarify anything, let me know.

Thank you!

I discovered item.*** yesterday too, and I think that may solve some of my other issues too