CMS Development


How can I map a HubDB column to a Choice field in a page module?

I have a simple request, but I don't know if it's not possible or if my code is wrong.

I have a custom page module with a choice field called "categories"

In this module, I am pulling data in from a Hubdb table and would like to map a column to the options of the Choice field. Can this be done?

Here is the code I have current

{% set currentList = [] %}
{% for row in hubdb_table_rows(0000000) %}
{% if currentList is not containing row.category %}
{% do currentList.append(row.category) %}
{% endif %}
{% endfor %}
{% set categoryChoices = currentList|join(', ') %}
{% choice "categories" label='Categories', value="{{currentList[0]}}" choices='{{ categoryChoices }}'%}

2 Replies 2
Top Contributor

How can I map a HubDB column to a Choice field in a page module?

Hi @TOReilly ,


I'm not sure I understand fully, but are you wanting a list of items to appear based on all the options within a HubDB column?


I recently did something similar whereby I needed to populate a list of items that would automatically pull through the contents within a select list column from HubDB. These links would open up a new page ID that is given to each item. You could probably leave that part out (query parameters) if you don't require links.


I've amended my code to your column name:


<!-- Filter -->
  <form id="filter" method="get">
    <select name="category" form="filter" onChange="this.form.submit()">
      <option value="show-all">Show All</option>
      {% set category = hubdb_table_column(0000000, "category").options %}
      {% for choice in category %}
        {% set category_list =|list %}   
          {% if == %}
            <option selected="selected" value="{{ }}">{{ }}</option>
          {% else %}
            <option value="{{ }}">{{ }}</option>
          {% endif %}
      {% endfor %}

<!-- Query Parameters -->
  {% set queryparam = "" %}
  {% if request.query_dict.category in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] %}
    {% set queryparam = queryparam ~ "&orderBy=category="~request.query_dict.category|urlencode %}
  {% endif %}
  {% if request.query_dict.category == "show-all" %}
      {% set queryparam = queryparam ~ "&orderBy=category" %}
  {% endif %}


HubSpot Product Team
HubSpot Product Team

How can I map a HubDB column to a Choice field in a page module?

@tmcmillan99 @ben-duchy   👋

Any chance one of you two could help here?



HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show