Liquid Templates

Created on 2023-09-03T13:23:33-05:00

Return to the Index

This card pertains to a resource available on the internet.

This card can also be read via Gemini.

only read about half or less. the basic idea is simple enough but there is actually quite a bit here to implement.

Objects: inserts someting in the page. Text inside of {{ and }}'s.

Filters: modifies values before sending them out to the user. These are specified inside objects, using pipes. Such as {{post | capitalize}}.

Tags: controls conditional rendering. Text inside of {% and %}'s.

Operators: ==, !=, >, <, >=, <=, or, and

Operators are checked right to left. Parenthesis are not allowed, so you can't change grouping.

All values are `true` except `nil` and `false.` Empty strings are still `true`.

Types: Strings, Numbers, Boolean, Nil, Array, EmptyDrop

EmptyDrop: a nil type that represents deleted or not-found data; ex. when looping over paginated data.

empty: you can check values against `empty`. comparing `== empty` is true if an array or string has zero elements.

Whitespace control: if a dash appears in a brace pair, whitespace is consumed from that side. {{-, -}}, {%-, and -%}

if 
elsif 
else 
endif

for  in 
  break    # exit loop early
  continue # next iteration
else
  .. code path if array is empty
endfor

# can include parameters
for  in  limit:2 offset:3 reversed

assign  = 
assign  = (low..high) # ranges

comment
  .. stuff
endcomment

`forloop` is a variable to access data about the current for loop.

Cycles and cycle groups give rotating groups of value while iterating.

Table row loops for creating HTML tables based on data in the template environment.