1

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 %}
    <ul>
    {% for row in block.codePoints %}
         {# Assuming 'text' is the column handle of the text field #}
        <li>{{ row.text }}</li> 
    {% endfor %}
    </ul>
{% endif %}

I can't find an example of:

<table>
<tr><td></td><td></td><td></td></tr>
</table>

Thanks.

2
  • 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
    Commented Dec 23, 2016 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
    Commented Dec 23, 2016 at 13:08

1 Answer 1

2

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

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

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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