DEV Community

loading...
Cover image for Wee update to my Diversity in Tech and Events Listings 11ty site

Wee update to my Diversity in Tech and Events Listings 11ty site

whykay 👩🏻‍💻🐈🏳️‍🌈 (she/her)
Volunteer: Coder, tech event organiser, mentor, advocates diversity in tech | Working as Maker Advocate
・2 min read

So I realised when I checked https://irish-diversity-in-tech.netlify.app/events/ - all was not as it seems...

There's no listings for either general tech events and diversity in tech events as it's the end of the month and it's March 1st tomorrow!

Let's "if" this thing


Right, so I only need to wrap the bits in an if statement. Let's see what I can do, maybe check the listings itself and if it's empty, display the message to say there's no listings this month and check the ARCHIVES (which contains past and upcoming events for both general techie events and diversity in tech events).

{% if listings %}
  Get events listings code...
{% else %}
  Display message that there's no more events this month, etc.
{% endif %}
Enter fullscreen mode Exit fullscreen mode

Added test events for today so I can see the listing appears, and if I remove it, the message should appear.

BUT... that didn't work!

Ok, used the handy dump to show what gets outputting from listings and I get [].

Hmm, ok, so it is empty, maybe we can get the length of the array returned, and if it's zero, then display the message.

{% if listings | length != 0  %}
  Get events listings code...
{% else %}
  Display message that there's no more events this month, etc.
{% endif %}
Enter fullscreen mode Exit fullscreen mode

And hey presto, that worked! 🙌

Added that check for diversity in tech events section as well, and tried adding test data and removing it to see the message or listing appears correctly.

So quick fix all committed back

And it all looks ok now!
Screenshot 2021-02-28 at 17.26.07

Discussion (0)