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.
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.
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.
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.