2

I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.

First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.

Second: I would like to be able to display these values so that they are in an ascending order.

  • I think you will need to be more specific, perhaps give a code example? – Roi Agneta Dec 31 '18 at 20:20
  • @RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value. – Aleks P Dec 31 '18 at 20:32
2

OK, one possible way is the use the value of the colour field in an if statement, something this:

{# list rows that have "blue" in the colour field #}
{% for row in table.fieldName %}
{% if row.colour == 'blue' %} // probably best to make "blue" a variable
    <li>{{ row.age }} - {{ row.provider }} - etc.</li>
{% endif %}

In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit

You could also do it with JavaScript, but that is nasty.

Here is the complete code using an Array to sort by the age field:

{% set tableBlock = [] %}
{% set tableRow = [] %} 

{% for row in entry.myTableField %} 
    {% if row.colour == "blue" %}

    {% set tableRow = {
        'age' : row.age,
        'colour' : row.colour,
        'provider' : row.provider
    } %}
{% set tableBlock = tableBlock|merge([tableRow]) %} 
    {% endif %}

{% endfor %}

{% for row in tableBlock|sort %}
    
  • {{row.age}} {{row.colour}} {{row.provider}}
  • {% endfor %}

    For some reason the code block formatting is not working...

    | improve this answer | |
    • Glad to be of help! – Roi Agneta Jan 1 '19 at 20:44

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

    Not the answer you're looking for? Browse other questions tagged or ask your own question.