CMS Development

ben-duchy
Contributeur de premier rang

Flexible table data

Résolue

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 Votes
2 Solutions acceptées
piersg
Solution
Conseiller clé

Flexible table data

Résolue

Hi @ben-duchy 

 

You could try this:

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

Voir la solution dans l'envoi d'origine

ben-duchy
Solution
Contributeur de premier rang

Flexible table data

Résolue

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

Voir la solution dans l'envoi d'origine

0 Votes
7 Réponses
piersg
Solution
Conseiller clé

Flexible table data

Résolue

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
Contributeur de premier rang

Flexible table data

Résolue

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 Votes
piersg
Conseiller clé

Flexible table data

Résolue

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 Votes
ben-duchy
Solution
Contributeur de premier rang

Flexible table data

Résolue

@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 Votes
piersg
Conseiller clé

Flexible table data

Résolue

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 Votes
ben-duchy
Contributeur de premier rang

Flexible table data

Résolue

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

0 Votes
ben-duchy
Contributeur de premier rang

Flexible table data

Résolue

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 Votes