Hi @sanntn Thanks for reaching out. Let’s see if we can get this conversation started — @alyssamwilie@Kevin-C@LMeert do you have any experience or insight here?
{% set country = "Armenia" %}
{% set country_query = "name__eq=" ~ country %}
{% set data = hubdb_table_rows(5424505) %}
{% set select_data = data|selectattr("name","eq",country) %}
{{ country }}<hr>
{% for item in select_data %}
{{ item.name }} - {{ item.gdp }}<br>
{% endfor %}
or
{% set country = "Armenia" %}
{% set country_query = "name__eq=" ~ country %}
{% set data = hubdb_table_rows(5424505, country_query) %}
{{ country }}<hr>
{% for item in data %}
{{ item.name }} - {{ item.gdp }}<br>
{% endfor %}
I’m trying ti figure out why this solution is not working for me.
If i use a value definition for country, like in the example, with a defined string as value, it works. However, when I assign the value for the country variable from another variable (a contact property value in my case) it fails and the selectattr returns zero results.
so
{% set country=“Armenia” %} works
but
{% set country= contact[‘country’] %}
will not result in a match, however, echoing both {{ country}} and {{contact[‘country’] }} shows me Armenia twice.
Comparing strings can be tricky! Look into using a few filters to clean up the strings comparing. Potential filters being; trim, lower, replace, and regex_replace.
Edit:
I would also check that the user is cookied before banging your head against the wall too many times!
Even if i set the value to match to equal the table row value, it does not find a match:
{% set rows = hubdb_table_rows(XXXX) %}
{% set test = hubdb_table_row(XXXX,YYYY) %}
{% set queryValue = test.title %}
{% set match = rows|selectattr(‘title’,‘eq’, queryValue ) %}
{{ match }}
renders: []
if test.title is not going to match with any row title field from the table it was taken, then there is something really wrong with selectattr. My guess is that there is something wrong with the parser, when the variable value is not known at compile time.