# HubDB Selection Field

**URL:** <https://community.hubspot.com/t/hubdb-selection-field/35226>\
**Category:** CMS Development\
**Tags:** design-manager, hubdb\
**Created:** [April 9, 2021, 11:16am UTC](https://community.hubspot.com/t/hubdb-selection-field/35226 "2021-04-09T11:16:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JLanfear](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jlanfear/32/95715_2.png) [@JLanfear](https://community.hubspot.com/u/JLanfear)\
**Post date:** [April 9, 2021, 11:16am UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/1 "2021-04-09T11:16:44Z")

</div>

Hi,

I am having some trouble with the HubDB Selection field, my basic idea is when we add new data to the HubDB we select a ‘Format’ that format can either be a download, a course, a video etc… What I am wanting to do is display an icon depending on what has been selected in that column.

I’m trying to loop through the ‘format’ column for each row, check what the selection is and if it’s ‘Download’ display a download icon, and so on and so forth.

Any help would be really appreciated. Thank you!

---

<div class="post-metadata">

**Author:** ![LucBenayoun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lucbenayoun/32/27465_2.png) [@LucBenayoun](https://community.hubspot.com/u/LucBenayoun)\
**Post date:** [April 9, 2021, 12:02pm UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/2 "2021-04-09T12:02:56Z")

</div>

Hey!

From what I understand, you currently set a “Format” field which is a dropdown select. From this field, you want to retrieve what is the data selected from this field and show an icon if this is the case right?

Well, follow this kind of logic and it should work 🙂

```lia-code-sample
{% set table = hubdb_table_rows(module.hubdbtable_field) %}
{% for row in table %}
{% if row.format.name|lower == "download" %}
// If format = download
{% else %}
// If format != download
{% endif %}
// Other code
{% endfor %}

```

Example with some HTML:

```lia-code-sample
{% set table = hubdb_table_rows(module.hubdbtable_field) %}
<div class='container'>
 <div class='row-fluid'>
 <h1>HubDB Example</h1>
 </div>
</div>
<div class='container'>
 <div class='row-fluid'>
 {% for row in table %}
 <div class='span4 columns'>
 <div class='category'>
 {% if row.format.name|lower == "download" %}<i class='download'>Icon</i>{% else %}{{ row.format.name }}{% endif %}
 </div>
 <h2>{{ row.name }}</h2>
 </div>
 {% endfor %}
 </div>
</div>

```

Cheers 🙂

---

<div class="post-metadata">

**Author:** ![JLanfear](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jlanfear/32/95715_2.png) [@JLanfear](https://community.hubspot.com/u/JLanfear)\
**Post date:** [April 9, 2021, 12:18pm UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/3 "2021-04-09T12:18:17Z")

</div>

Don’t think that works, think you are on the right path though,

basically, I have a column in my hubdb where when we add new content you select either: Download, Article, Podcast, Video, Website, Course or Interview. On the resource (see below) I want to print an icon depending on what is selected.

I think the if condition to see if the name is download is right but that just prints 7 download icons rather than one because there are seven rows that have selected download.

 ![40669iC98DBDA37C354141.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/3/2/32c8c3e5813363d8c4adfd0d6a0b3610c6f48d48.png)

---

<div class="post-metadata">

**Author:** ![LucBenayoun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lucbenayoun/32/27465_2.png) [@LucBenayoun](https://community.hubspot.com/u/LucBenayoun)\
**Post date:** [April 9, 2021, 12:38pm UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/4 "2021-04-09T12:38:11Z")

</div>

I’m not sure to fully understand. I tested with a HubDB, here are my screenshots.

 ![40676i17986A064FFC16BC.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/3/73ddb71bc8207d104e1a17031d8c351949da9510.png)

 ![40677iCD830104652347CD.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/e/de90f05779bf8f9e77839235e7cc7809a640c916.png)

Tell me what I’m missing and I’ll be happy to help! 😉

---

<div class="post-metadata">

**Author:** ![JLanfear](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jlanfear/32/95715_2.png) [@JLanfear](https://community.hubspot.com/u/JLanfear)\
**Post date:** [April 9, 2021, 1:56pm UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/5 "2021-04-09T13:56:19Z")

</div>

Sorry man, it’s probably me, when I input your code this is what I get.

 ![40679iDFCF58577B68B8D4.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/0/0c5868aeaa9bd6980f9831d94cfffdc0ad97cd14.png)

Am I supposed to change some values to my own? Again sorry not well versed in this department.

---

<div class="post-metadata">

**Author:** ![LucBenayoun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lucbenayoun/32/27465_2.png) [@LucBenayoun](https://community.hubspot.com/u/LucBenayoun)\
**Post date:** [April 9, 2021, 2:03pm UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/6 "2021-04-09T14:03:29Z")

</div>

I think it should be better that you paste you module code in here so I can take a look but you’re probably looping in another loop 🙂

---

<div class="post-metadata">

**Author:** ![JLanfear](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jlanfear/32/95715_2.png) [@JLanfear](https://community.hubspot.com/u/JLanfear)\
**Post date:** [April 9, 2021, 2:11pm UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/7 "2021-04-09T14:11:00Z")

</div>

This is the section of code for the resource listing part of the module, your addition is in bold.

\<div class=“resource-body”\>  
{% set table = hubdb\_table\_rows(3411941, queryparam) %}  
\<div class=“rlpp-grid rlpp-grid-3col”\>  
{% if table == [] %}  
\<p class=‘align-center’ style=“color: #2a2a2a; width: 100%;”\>Sorry, no listings found for that Search. Try changing your filter and search again.\</p\>  
{% else %}  
{% for row in table %}

\<div class=“resource-listing”\>

\<a href=" {{ row[“link”] }} " target=“\_blank” style=“color: #fff;”\>  
**\<div class=“resource–format\_\_icon”\>**  
**{% set table = hubdb\_table\_rows(module.hubdbtable\_field) %}**  
**{% for row in table %}**  
**{% if row.format.name|lower == “download” %}**  
**\<i class=“fas fa-download”\>\</i\>**  
**{% else %}**  
**{% endif %}**

**{% endfor %}**  
\</div\>  
\<div class=“image-container”\>\<img src=“{{ row[“image”].url}}”\>\</div\>  
\<div class=“category-display-container” style=“color: #dd083b;”\>{{ row[“type”].name }}\</div\>  
\<h4 style=“color: #2a2a2a; text-align: center;”\>{{ row[“title”] }}\</h4\>  
\<p style=“color: #2a2a2a; text-align: center;”\>{{ row[“description”] }}\</p\>

\<div class=“view-button-container”\>  
\<button class=“view-button”\>View Resource\</button\>  
\</div\>

\</a\>  
\</div\>  
{% endfor %}  
{% endif %}  
\</div\>  
\<div class=“loadmore-container”\>  
\<a href=“#” id=“loadMore”\>Load More\</a\>  
\</div\>

\</div\>

---

<div class="post-metadata">

**Author:** ![LucBenayoun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lucbenayoun/32/27465_2.png) [@LucBenayoun](https://community.hubspot.com/u/LucBenayoun)\
**Post date:** [April 9, 2021, 2:21pm UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/8 "2021-04-09T14:21:57Z")

</div>

Okay that’s what I was thinking. By copy/paste my code you’re looping inside an existing loop your created before. Replace all HubL code with this:

```lia-code-sample
{% set table = hubdb_table_rows(3411941, queryparam) %}
<div class="rlpp-grid rlpp-grid-3col">
 {% if table == [] %}
 <p class='align-center' style="color: #2a2a2a; width: 100%;">Sorry, no listings found for that Search. Try changing your filter and search again.</p>
 {% else %}
 {% for row in table %}
 <div class="resource-listing">
 <a href=" {{ row["link"] }} " target="_blank" style="color: #fff;">
 <div class="resource--format__icon">
 {% if row.format.name|lower == "download" %}
 <i class="fas fa-download">Icon</i>
 // Other code like name and so on
 {% else %}
 // Other code like name and so on
 {% endif %}
 </div>
 </a>
 </div>
 {% endfor %}
 {% endif %}
</div>

```

Let me know! 🔥

---

<div class="post-metadata">

**Author:** ![JLanfear](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jlanfear/32/95715_2.png) [@JLanfear](https://community.hubspot.com/u/JLanfear)\
**Post date:** [April 9, 2021, 2:37pm UTC](https://community.hubspot.com/t/hubdb-selection-field/35226/9 "2021-04-09T14:37:50Z")

</div>

Thank man you did it! Really appreciate your help, you’re a lifesaver!

 ![40682iF939828AF1B41ABE.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/1/3/13f76f6a21fa58e3ea8424685f60b642a6ee2325.png)
