Checking if a variable is set in Jekyll
This site is built using Jekyll which allows me to generate the entire thing as static html which can then be hosted on AWS S3. Working through the Jekyll documentation I couldn't find a way to check if a variable was set when coding in Jekyll's templating language Liquid.
This is easy in python and javascript but after some digging I found this Github issue thread which (after a lengthy discussion) came up with the following as best practice...
Script to check if a variable is set in Jekyll
{% if page.some_variable And page.some_variable != "" And page.some_variable != nil %}
{{some_variable}}
{% else %}
some_variable is not set
{% endif %}
The "nil" check was specifically tripping me up. Hopefully this helps someone else out there.
To: @mattccrampton
0
Other Posts
When exporting photos from a service like Flickr, perhaps after they've given notice that they're going to delete our photos if you don't subscribe to......
All Truthy and Falsy Javascript Values In Nodejs, every value has an associated boolean, true or false, value. For example, a null value has an......
Google Forcing Nest Cameras Visual Indicator Light To Be On Received the following email from Google today... Full email text... Recently, we shared our commitment......
Posting to Twitter with Python - Part Two: Posting Photos NOTE: This is part two of my posting to Twitter with Python tutorial. If you......
Doubleclick to open a file in VIM from OSX I use VIM for just about everything from note taking to coding to keeping track of......
Sign Into Gmail Without Signing Into Google Chrome Unfortunately, Google has made changes to Chrome since this blog post was posted which removed the options......