zebra
zebra

Reputation: 6531

How to programatically insert HTML in a Django template based on attributes in a model

In my view, I am receiving a list of Events. 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

Answers (1)

Jody Fitzpatrick
Jody Fitzpatrick

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

Related Questions