Hi,
Sorry, this may just be the end of week Friday brain kicking in and I’ve missed something obvious.
I have a HubDB, and I’m currently creating a page that displays options available in a multi-select field, alongside titles associated with that selection.
What I’m trying to do is have whichever Category selected to appear in the “FAQ -” title.
Similar to how the team member example page does it here. Unfortunately, they do not tell you in the tutorial how to set that up. It bypassed that part:
{% set types = hubdb_table_column(dynamic_page_hubdb_table_id, "category_select").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list%}
{% if choice.id == request.query_dict.category_select%}
<p><a href="{{ request.path }}?category_select={{ choice.id }}">{{ choice.name }}</a></p>
{% else %}
<p><a href="{{ request.path }}?category_select={{ choice.id }}">{{ choice.name }}</a></p>
{% endif %}
{% endfor %}
</div>
<div class="kc-faq-wrapper mobile-top">
{% set queryparam = "&orderBy=order" %}
{% if request.query_dict.category_select in ["1", "2", "3", "4", "5"] %}
{% set queryparam = queryparam ~ "&category_select__contains="~request.query_dict.category_select %}
{% endif %}
{% if request.query_dict.category_select == "show-all" %}
{% set queryparam = queryparam %}
{% endif %}
<h2>
FAQ -
</h2>
{% for row in hubdb_table_rows(dynamic_page_hubdb_table_id, queryparam) %}
<div>
<div class="faq-btn" data="img{{loop.index}}">
<p><span><a href="{{ request.path }}/{{ row.hs_path }}">{{ row.title }}</a></span>
<img class="plus" src="https://cdn2.hubspot.net/hubfs/4351639/2019/assets-may-2019/plus-bold.svg" alt="plus symbol">
</p>
</div>
</div>
{% endfor %}
</div>
Hiya @pm8rsh88 ,
What you could do is first create a variable to hold the selected option. Then in your for loop of the choices, in the if statement checking id against url query, update the selected variable with the selected choice name. Then you can use that variable to print the name wherever you want it.
{% set types = hubdb_table_column(dynamic_page_hubdb_table_id, "category_select").options %}
{#### set variable to hold currently selected choice name ####}
{% set selected = {} %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list%}
{% if choice.id == request.query_dict.category_select%}
{#### update selected variable ####}
{% do selected.update({'name': choice.name}) %}
<p><a href="{{ request.path }}?category_select={{ choice.id }}">{{ choice.name }}</a></p>
{% else %}
<p><a href="{{ request.path }}?category_select={{ choice.id }}">{{ choice.name }}</a></p>
{% endif %}
{% endfor %}
</div>
<div class="kc-faq-wrapper mobile-top">
{% set queryparam = "&orderBy=order" %}
{% if request.query_dict.category_select in ["1", "2", "3", "4", "5"] %}
{% set queryparam = queryparam ~ "&category_select__contains="~request.query_dict.category_select %}
{% endif %}
{% if request.query_dict.category_select == "show-all" %}
{% set queryparam = queryparam %}
{% endif %}
<h2>
{#### Use selected variable to print the selected choice name ####}
FAQ - {{ selected.name }}
</h2>
{% for row in hubdb_table_rows(dynamic_page_hubdb_table_id, queryparam) %}
<div>
<div class="faq-btn" data="img{{loop.index}}">
<p><span><a href="{{ request.path }}/{{ row.hs_path }}">{{ row.title }}</a></span>
<img class="plus" src="https://cdn2.hubspot.net/hubfs/4351639/2019/assets-may-2019/plus-bold.svg" alt="plus symbol">
</p>
</div>
</div>
{% endfor %}
</div>
Thank you! I don’t know why I didn’t think of using a Variable. My brain most have seriously crashed on Friday.
It works perfectly, thanks