CMS Development

ben-duchy
トップ投稿者

Flexible table data

解決

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 いいね!
2件の承認済みベストアンサー
piersg
解決策
キーアドバイザー

Flexible table data

解決

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
解決策
トップ投稿者

Flexible table data

解決

@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 いいね!
7件の返信
piersg
解決策
キーアドバイザー

Flexible table data

解決

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
トップ投稿者

Flexible table data

解決

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 いいね!
piersg
キーアドバイザー

Flexible table data

解決

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 いいね!
ben-duchy
解決策
トップ投稿者

Flexible table data

解決

@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 いいね!
piersg
キーアドバイザー

Flexible table data

解決

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 いいね!
ben-duchy
トップ投稿者

Flexible table data

解決

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

0 いいね!
ben-duchy
トップ投稿者

Flexible table data

解決

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 いいね!