CMS Development

ben-duchy
Top Contributor

Flexible table data

SOLVE

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

0 Upvotes
2 Accepted solutions
piersg
Solution
Key Advisor

Flexible table data

SOLVE

Hi @ben-duchy 

 

You could try this:

{% set choice = module.plotstatus %}
{% set table = hubdb_table_rows(module.table_id, "plot-status=" ~ choice ~ "&orderBy=class") %}

View solution in original post

ben-duchy
Solution
Top Contributor

Flexible table data

SOLVE

@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 %}

View solution in original post

0 Upvotes
7 Replies 7
piersg
Solution
Key Advisor

Flexible table data

SOLVE

Hi @ben-duchy 

 

You could try this:

{% set choice = module.plotstatus %}
{% set table = hubdb_table_rows(module.table_id, "plot-status=" ~ choice ~ "&orderBy=class") %}
ben-duchy
Top Contributor

Flexible table data

SOLVE

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?

0 Upvotes
piersg
Key Advisor

Flexible table data

SOLVE

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") %} 

 

0 Upvotes
ben-duchy
Solution
Top Contributor

Flexible table data

SOLVE

@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 %}

0 Upvotes
piersg
Key Advisor

Flexible table data

SOLVE

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") %}

 

0 Upvotes
ben-duchy
Top Contributor

Flexible table data

SOLVE

Thanks @piersg, I'll give it a go when I get a sec - thanks again for your help previously

0 Upvotes
ben-duchy
Top Contributor

Flexible table data

SOLVE

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?

0 Upvotes