How to create events feed that automatically removes events after their date of occurrence

Celmer93
Participant | Diamond Partner

We have an events feed on our client's website that was put in place just as a standard module that needs to be updated manually to remove events once they happen. Is there a way to set this up so that the events are removed automatically once it is past the date that they happen?

Was my post helpful? If so, please mark it as a solution.
0 Upvotes
1 Reply 1
Jsum
Key Advisor

@Celmer93,

 

I did this fun little test. I'm not sure if it woudl be to complicated for you to implement but it will work if you can use it. Basically I created choice modules that would allow you to input the expiration day, month, and year. 

 

I then assigned these values to variables, compares them to the current day, month, and year, and if the date has past it prints "hide_event" as a class for a div that would contain your event markup. You would set your css for that class to "display: none" and if the current date passes the set expiration date for the event it would hide the event. Now the question becomes how to allow you to create multiple events. Let me know if this helps and I will play with that part. 

{% set day = local_dt|datetimeformat('%d')|int %}
         {% set month = local_dt|datetimeformat('%m')|int %}
         {% set year = local_dt|datetimeformat('%Y')|int %}
         
         {% choice "day" label='Expire Date Day', value='08', choices='01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31' export_to_template_context=True %}
         {% choice "month" label='Expire Date Month', value='06', choices='01,02,03,04,05,06,07,08,09,10,11,12' export_to_template_context=True %}
         {% choice "year" label='Expire Date Year', value='2019', choices='2017,2018,2019,2020' export_to_template_context=True %}
         
         {% set expDay = widget_data.day.value|int %}
         {% set expMonth = widget_data.month.value|int %}
         {% set expYear = widget_data.year.value|int %}
        
         
     <div class="{% if year > expYear %}
         {% elif year <= expYear %}
            {% if month > expMonth %}
            {% elif month <= expMonth %}
                {% if day > expDay %}
                {% elif day <= expDay %}
                     hide_event
                {% endif %} 
            {% endif %}
         {% endif %}">

{# Markup #}
</div>


You could also place your markup within the if statement so that there is no need to hide it with "display: none" because it will not print to from the server it the date conditions are not met:

     {% if year > expYear %}
         {% elif year <= expYear %}
            {% if month > expMonth %}
            {% elif month <= expMonth %}
                {% if day > expDay %}
                {% elif day <= expDay %}
                     
                     {# markup #}

                {% endif %} 
            {% endif %}
         {% endif %}\
0 Upvotes