Twig for loop, how do I display the last element?

Viewed 12281

Here's my code.

<th>Attachment</th>
                <td>
                    <ul>
                        {% for attachment in lineup.attachments %}
                        <li><a href='http://files.example.com/{{ attachment.file_url }}'>{{ attachment.name }}</a>
                        {% endfor %}
                    </ul>
                </td>

This is posting EVERY attachment which is great but I just want it to post the last attachment it finds while iterating through the attachments table. For instance if it finds 10 attachments, I don't want all of them, just the 10th one. Is there anyway to do this?

2 Answers
Related