Reputation: 6531
In my view, I am receiving a list of Event
s. I want to display them on a timeline, where a header gets rendered for each new date, but multiple events on the same date at different times can get grouped under that single header.
In this scenario, I only want to display the header containing the date if the date is different than the Event
that was rendered before it (I'm assuming the best way to iteratively render them is with something like {% for event in events %}
)
How can I decide to render a certain html block only if event.date
is different than the previously rendered event.date
?
Upvotes: 1
Views: 2397
Reputation: 357
I think what you want to go after is the ifchanged.
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifchanged
Upvotes: 2