This page covers pitfalls to be aware of when writing content for the site.
This site uses Markdown for rich text formatting. It is powerful and friendly, but not a full replacement for raw HTML. Fortunately, you can mix HTML into your Markdown, as long as you are careful!
Mixing Markdown and HTML
You can apply CSS styles to inline HTML elements such as <span>
,
and any nearby Markdown will still be applied:
Code
Result
Enjoy some colored text in italics!
Markdown inside block elements
If you use a block element, Markdown won’t be rendered inside:
Code
Result
Add markdown=1
to force Markdown rendering inside that element:
Code
Result
Yay, this is now in italics!
Be sure to put a newline before your </div>
! Otherwise you will get broken HTML. (Might be a bug in the Kramdown renderer?)
To avoid the pitfall with </div>
and newlines, you can instead
target the parts you want Markdownified using <span markdown=1>
:
Code
Result
Suppressing Markdown rendering
The markdown
attribute can also be used the other way, to suppress
Markdown rendering inside an HTML element:
Code
Result
Here are some **asterisks**.
Conditional expressions
Where conditionals work
Conditional expressions may only be used with if
and unless
tags!
They notably do not work with assign
tags. So you cannot write a
truthy conditional expression and assign it to variable expecting it
to be set as true
or false
. If you need that, you can write:
Truthiness and falsiness
In Liquid, the only conditional expressions that evaluate to false are
false
and nil
.
Unlike other languages, in Liquid even the empty string (''
)
and the number zero (0
) evaluate to true
!
Table of truthy and falsy example expressions
Expression | truthiness |
---|---|
"have a cow" | true |
"" | true |
nil | false |
nil or "" | true |
nil or "" or "hello" or "goodbye" | true |
"" or "hello" or "goodbye" | true |
"hello" or "goodbye" | true |
nil or "" | true |
"" or nil | true |
true or false | true |
false or true | true |
true or true | true |
false or false | false |
true or nil | true |
nil or true | true |
false or nil | false |
nil or false | false |
false or nil or true | true |
nil or false or true | true |
nil and "" | false |
"" and nil | false |
true and false | false |
false and true | false |
true and true | true |
false and false | false |
true and nil | false |
nil and true | false |
false and nil | false |
nil and false | false |
false and nil and true | false |
nil and false and true | false |
Order of operations
Unlike other languages, the and
and or
operators in Liquid have the same
precedence. And even more surprisingly, Liquid
evaluates conditionals from right to left with equal operator
precedence.
Here is an example:
equals false.
Here is a breakdown of how Liquid is evaluating the above:
→ nil and ('me' or ('yes' and 'OK'))
→ nil and ('me' or true)
→ nil and true
→ false
The parentheses above are merely for illustration; Liquid does not support parentheses in conditional expressions and your expression will be wrongly evaluated if you try to use them.
In most other languages such as Python or JavaScript, it would be true
:
$ js
> console.log(null && 'me' || 'yes' && 'OK' ? 'true' : 'false')
true
$ python
>>> print('true' if None and 'me' or 'yes' and 'OK' else 'false')
true