We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Jul 22, 2020 6:31 AM - edited Jul 22, 2020 6:33 AM
Is it possible to add a choice field within the 'set table' line?
Currently I have the following line of code which works fine:
{% set table = hubdb_table_rows(module.table_id, "plot-status=Released&orderBy=class") %}
However I would like to add in a choice field {{ module.plotstatus }} to allow the content editor to select which hubdb data to display. Is this possible?
I've tried replacing "plot-status="Released with
plot-status={{ module.plotstatus }} but it doesnt work!
Thanks in advance
Solved! Go to Solution.
Jul 22, 2020 8:00 AM
Hi @ben-duchy
You could try this:
{% set choice = module.plotstatus %}
{% set table = hubdb_table_rows(module.table_id, "plot-status=" ~ choice ~ "&orderBy=class") %}
Jul 22, 2020 10:26 AM
@piersg I've found a fix, although probably not the prettiest coding I've ever done...
{% set choice = module.select_status %}
{% if choice == "Available" %}
{% set table = hubdb_table_rows(module.table_id, "&plot-status__in=Available,SpecialOffer&orderBy=price&orderBy=class") %}
{% else %}
{% set table = hubdb_table_rows(module.table_id, "plot-status=" ~ choice ~ "&orderBy=class") %}
{% endif %}
Jul 22, 2020 8:00 AM
Hi @ben-duchy
You could try this:
{% set choice = module.plotstatus %}
{% set table = hubdb_table_rows(module.table_id, "plot-status=" ~ choice ~ "&orderBy=class") %}
Jul 22, 2020 8:27 AM
Genius! Thanks very much.
In addition to this, is it possible build on this command to pull in extra data but only if a particlar selection is made?
As it stands the relevant row will only show if the content editor selects it, but if they select for example "Available" from the choie field, can it also show "SpecialOffer" fields too and vice versa?
Jul 22, 2020 9:26 AM
So you want to add an aditional filter, SpecialOffer, to the table call when "Available" is selected from the plot status choice?
{% set choice = module.plotstatus %}
{% if choice == "Available" %}
{% set choice = choice ~ "&SpecialOffer=[value]" %}
{% endif %} {% set table = hubdb_table_rows(module.table_id, "plot-status=" ~ choice ~ "&orderBy=class") %}
Jul 22, 2020 10:26 AM
@piersg I've found a fix, although probably not the prettiest coding I've ever done...
{% set choice = module.select_status %}
{% if choice == "Available" %}
{% set table = hubdb_table_rows(module.table_id, "&plot-status__in=Available,SpecialOffer&orderBy=price&orderBy=class") %}
{% else %}
{% set table = hubdb_table_rows(module.table_id, "plot-status=" ~ choice ~ "&orderBy=class") %}
{% endif %}
Jul 22, 2020 10:54 AM
Haha well if it works, it works. In my earlier response I didn't understand that "SpecialOffer" was also an option from plot-status, so apologies for that.
If you wanted to cut a couple of lines you could do this:
{% set choice = "plot-status=" ~ module.select_status %} {% if choice is string_containing "Available" %} {% set choice = "&plot-status__in=Available,SpecialOffer&orderBy=price" %} {% endif %} {% set table = hubdb_table_rows(module.table_id, choice ~ "&orderBy=class") %}
Jul 22, 2020 10:59 AM
Thanks @piersg, I'll give it a go when I get a sec - thanks again for your help previously
Jul 22, 2020 10:15 AM
Yes thats correct - I'm trying to get it to pull in both sets of data but only if 'Available' is selected.
This hasn't worked, but I see where you're going with it, so thanks all the same.
I'll see if I can figure it... out unless you have any other ideas?