CMS Development

tmitch_sona
Participant

Struggling to loop through multi-select options from HubDB

SOLVE
Hi - marketer more than a developer here. I'm having some problems with what I think should be a super basic for loop. I'm embedding a module that pulls the value of a dropdown-select column from a specified row:
{% module "our_products" path="@hubspot/text",
  label='Our Products',
  value={{hubdb_table_row('quote_breakdown_pages', lookuprow).our_products}},export_to_template_context=True
%}
widget_data.our_products.value  then displays for example:
[{"id":1,"name":"Scheduling","label":"Scheduling","type":"option","order":0}, {"id":3,"name":"Wellbeing","label":"Wellbeing","type":"option","order":2}, {"id":4,"name":"Connect","label":"Connect","type":"option","order":3}]
But the below loop is printing absolutely nothing.
{% for product in widget_data.our_products.value %}
    {{ product.name }} <br>
{% endfor %}
Is this potentially to do with the speechmarks in the key value pairs? I'm sure I'm doing something completely daft here but can't work out what it is. Any suggestions massively appreciated!

 

0 Upvotes
1 Accepted solution
BarryGrennan
Solution
Top Contributor

Struggling to loop through multi-select options from HubDB

SOLVE

Hi @tmitch_sona,

 

Meant to reply earlier but I was having a bit of trouble visualing what you're going for. I think I get it now. (Thanks for the poke @Jaycee_Lewis 😁)

 

My guest would be that you can't achieve what you're going for with a text module (@hubspot/text). I haven't tested it out but I'd assume the text module just spits it out as a string of text, so you can't itterate through it like an array.

 

What I'd suggest doing instead is creating a custom module, that's be something like:

{% set product_list = hubdb_table_row('quote_breakdown_pages', lookuprow).our_products %}

{% for product in product_list  %}
    {{ product.name }} <br>
{% endfor %}

 

Then just include the module in your template where you need it. Unless I'm overlooking something (i.e. what it "export_to_template_context=True" is being used for.

 

Or you might not even need a custom module if the above code could be put directly in your template.

 

If I've totally missed the mark let me know and if possible provide the full template.

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

View solution in original post

0 Upvotes
4 Replies 4
BarryGrennan
Solution
Top Contributor

Struggling to loop through multi-select options from HubDB

SOLVE

Hi @tmitch_sona,

 

Meant to reply earlier but I was having a bit of trouble visualing what you're going for. I think I get it now. (Thanks for the poke @Jaycee_Lewis 😁)

 

My guest would be that you can't achieve what you're going for with a text module (@hubspot/text). I haven't tested it out but I'd assume the text module just spits it out as a string of text, so you can't itterate through it like an array.

 

What I'd suggest doing instead is creating a custom module, that's be something like:

{% set product_list = hubdb_table_row('quote_breakdown_pages', lookuprow).our_products %}

{% for product in product_list  %}
    {{ product.name }} <br>
{% endfor %}

 

Then just include the module in your template where you need it. Unless I'm overlooking something (i.e. what it "export_to_template_context=True" is being used for.

 

Or you might not even need a custom module if the above code could be put directly in your template.

 

If I've totally missed the mark let me know and if possible provide the full template.

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

0 Upvotes
tmitch_sona
Participant

Struggling to loop through multi-select options from HubDB

SOLVE

Thanks so much @BarryGrennan  - yes I've ended up going for a module level solution here rather than getting it to work at a global level. Appreciate your help!

BarryGrennan
Top Contributor

Struggling to loop through multi-select options from HubDB

SOLVE

Great! glad I colud help!

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

Jaycee_Lewis
Community Manager
Community Manager

Struggling to loop through multi-select options from HubDB

SOLVE

Hey, @tmitch_sona 👋 Thanks for reaching out. Please note, there is no technical (or otherwise) gatekeeping here, ALL are welcome to post, share and learn.

 

Let's see if we can get the conversation going — @BarryGrennan @LMeert @Stephanie-OG, do you have any tips you can share with @tmitch_sona?

 

Thank you very much for taking a look! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes