I have the following code in my template:
{% for f in friendslist %}
{% if forloop.first %}
// display something
{% endif %}
// display stuff
{% if forloop.last %}
// display something
{% endif %}
{% endfor %}
It works as expected when there is more than one item in the friendslist. But if there is just 1 item, then the content inside the forloop.last
conditional does not display.
I guess this is because the loop in that case is the first, but I mean it’s also the last right? So why dosn’t both contents inside first and last
conditional show?
In my code they both execute if there is only one element in friendslist. Here is a test you can run in the shell where maybe you can figure out what isn’t working: