CMS Development

rnoon-d22
Member | Diamond Partner
Member | Diamond Partner

HubDB conditionals not displaying correct content

Hi guys,

 

I'm having a few issues with my conditional statements using HubL and HubDB. Basically I've got a table which has Events and Webinars combined. The events are ones which last more than a day, eg. 3 Aug to 5 Aug. The Webinars are one-day events. So what I'm trying to achieve here is to check if the Start Date and the End Date are the same then only display the End Date column, however, if they don't match then display both the Start and End Date columns.

 

The following scenarios are occurring: 

 

- Even when the Start Date and End Date don't match, it's still displaying the first if condition
- When I remove the first if condition, no date is displayed at all


Obviously something I'm missing here, any ideas?

 

The code I'm referring to is:

 

<div class="event-date">
    {% if dynamic_page_hubdb_row.event_start_date|datetimeformat('%B %e, %Y') == dynamic_page_hubdb_row.event_end_date|datetimeformat('%B %e, %Y') %}
        <div class="event-date__content"> <span class="end-date"> {{ row.event_end_date|datetimeformat('%B %e, %Y') }}</span></div>    
    {% endif %}
    {% if dynamic_page_hubdb_row.event_start_date|datetimeformat('%B %e, %Y') != dynamic_page_hubdb_row.event_end_date|datetimeformat('%B %e, %Y') %}
        <div class="event-date__content">{{ row.event_start_date|datetimeformat('%B %e, %Y') }} <span class="end-date"> - {{ row.event_end_date|datetimeformat('%B %e, %Y') }}</span></div>
    {% endif %}
</div>

 

1 Reply 1
tjoyce
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

HubDB conditionals not displaying correct content

@rnoon-d22 - I'm not entirely sure what you're intention is when you make your comparison on the dates but, if you are looking to check against an exact date/time/second then you shouldn't apply the filter of datetimeformat while making your if statement. 

The only reason I can see you getting unwanted results is because you're converting your date to a 24 hour range. For example: 

1531826070870 (timestamp converts to  July 17, 2018)
then, if I change the milliseconds of the timestamp
1531826070900 (timestamp also converts to  July 17, 2018)

So, if I were to check these 2 timestamps against each other after applying the datetimeformat filter, it would eval to TRUE since the result of both falls in the same day, even though the original timestamp is different.

Let us know if that is the case. If not, try adding the pprint filter to both of your dates and we can help you debug further.

{{ dynamic_page_hubdb_row.event_start_date|datetimeformat('%B %e, %Y')|pprint }}

If this answer helped, please, mark as solved 😄


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.

0 Upvotes