Need a hand on a conditional to see if my table has any data, and if it does, output the table. The second thing I need help is the code to output the table. When I look at tutorials, they always seem to output the table as an HTML list. Like:

   {% if block.codePoints | length %}
    {% for row in block.codePoints %}
         {# Assuming 'text' is the column handle of the text field #}
        <li>{{ row.text }}</li> 
    {% endfor %}
{% endif %}

I can't find an example of:



  • Is block a Matrix block? If so, what type of field is codePoints? Or is block the name of an entry and codePoints is a table field? – Brad Bell Dec 23 '16 at 3:31
  • I'm unclear about the example code. It isn't my code but what I found on Stack Exchange. I just used it as an example. I can't seem to find an example to output a table using <table> mark-up. And also need to check to see if table is blank. Each table has 1 row of blank so my condition is failing. – DevServe Dec 23 '16 at 13:08

Assuming your example code, something along these lines will help...

{% if entry.yourTable | length %}
    {% for row in entry.yourTable %}
       <td>{{ row.column1 }}</td><td>{{ row.column2 }}</td><td>{{ row.column3 }}</td>
    {% endfor %}
{% endif %}

Here's the relevant section in the docs: Table fields

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.