- Issue created by @gaia
- 🇮🇳India sidharth_soman Bangalore
Not sure if this is the best way to go about doing this, but you can achieve this like so:
1) Exclude all the fields in your view from display.
2) Edit the event date field in your view to use a plain formatter. We need the date string only, not the html element.
3) Add a 'Custom Text' field into your view. Here, we will render the event fields manually and add logic to differentiate the classes using twig templating.Here's the code I used to introduce a new class of old-event into the div which renders the individual events.
{% set currentDate = "now"|date("U") %} {% set dateField = field_event_date|date("U") %} {% set timeDifference = currentDate - dateField %} {% set daysDifference = timeDifference/86400 %} {% if daysDifference > 30 %} <div class="event-card old-event"> {% else %} <div class="event-card"> {% endif %} {{ title }} {{ field_event_date }} </div>
- 🇩🇪Germany gaia
Hey sidharth_soman! Thank you very much, this is exactly, what i needed.
- Status changed to Fixed
4 months ago 6:33pm 28 July 2024 Automatically closed - issue fixed for 2 weeks with no activity.