Reputation: 8648
I have the following for
loop that spits out all photos in a list:
{% if photos %}
{% for photo in photos %}
{% thumbnail photo.photo "100x100" crop="center" as im %}
<img src="{{ im.url }}" alt="User's photos" data-ajax="{% url 'photo_increase_view' pk=photo.id %}"/>
{% endthumbnail %}
{% endfor %}
{% endif %}
How can edit this to ignore the first result in the list (i.e. display items 2, 3, 4... etc)
Upvotes: 2
Views: 2055
Reputation: 747
Check out forloop.first
using Django; for example:
{% if photos %}
{% for photo in photos %}
{% if not forloop.first %}
{% thumbnail photo.photo "100x100" crop="center" as im %}
<img src="{{ im.url }}" alt="User's photos" data-ajax="{% url 'photo_increase_view' pk=photo.id %}"/>
{% endthumbnail %}
{% endif %}
{% endfor %}
{% endif %}
Upvotes: 4
Reputation: 2451
I guess the answer it's a bit late. But a solution is:
{% for photo in photos[1:] %}
.....
{% endfor %}
Upvotes: 4
Reputation: 3288
Use slice
Replace
{% for photo in photos %}
by
{% for photo in photos|slice:"1:" %}
So , complete code
{% if photos %}
{% for photo in photos|slice:"1:" %}
{% thumbnail photo.photo "100x100" crop="center" as im %}
<img src="{{ im.url }}" alt="User's photos" data-ajax="{% url 'photo_increase_view' pk=photo.id %}"/>
{% endthumbnail %}
{% endfor %}
{% endif %}
Upvotes: 5