Frequently Asked Questions

Using Liquid Logic to Check if a field exists, or is empty on the Front End

2min
how to check if a variable exists/ is null/ is false? not all the variables on siteglide will be stored as either "true" or "false" in many scenarios something may exist in one location, and simply not exist in another to better explain this i'll use a homepage as an example whether a page is the homepage or not is determined by the is homepage variable is homepage which has the value true however if a page is not the homepage, rather than is homepage being set to false , the is homepage variable doesn't exist say i wanted to run some code on every page that isn't the homepage, i'd write something like this {% if context page metadata is homepage == false %} output content {% else %} output homepage content {% endif %} this would work fine if we were on the homepage, as the variable's value would be true however, on other pages, it would not behave as expected, as is homepage would be undefined now lets look at the liquid keyword "blank" this refers to having a value of either empty, null or false if i now check "is homepage" like so {% if context page metadata is homepage == blank %} output content {% else %} output homepage content {% endif %} this will now work!