I'm working on a Liquid template in Jekyll, and I have 2 places where I'm not sure what to use: nil, null, or just empty.
In the front matter:
---
layout: nil|null|<empty>
---
nil, I get `Build Warning: Layout 'nil' requested in sitemap.xml does not exist, as this thread demonstrates.null and blank both have no error.In Liquid templating:
{% if post.date != nil %}
null, nil, and blank all work, but "" makes the statement true, when the variable is not set.So which should I use? Why? (Does this have anything to do with Ruby? I didn't add the tag.)
For the front matter, use null (as you've already seen). The front matter is interpreted as YAML which defines a null value as null (and possibly also with a tilde ~ though I've never tried that).
In the liquid templates, for the most part you'd be better off with leaving the comparison out:
{% if post.date %}
As that typically achieves what you're trying to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With