Keyword literals
Mechanic's Liquid implementation includes three new literals:
newline
–"\n"
hash
–{}
array
–[]
Use newline
to more easily navigate strings, and hash
and array
to quickly construct your own data structures.
Because these are literals, these keywords cannot be overwritten as variables.
Hash and array
These literals may be used for initializing variables, and then assigning within them. Learn more about the assign tag.
Why "hash"?
The term comes from Ruby, the language beneath Liquid. In Ruby (docs), "A Hash is a dictionary-like collection of unique keys and their values." In Mechanic's Liquid implementation, a hash can only have string keys.
Newline
Besides its natural uses in building strings, newline
has a special purpose within these string filters:
newline_to_br
– When used withnewline
, this filter will replace instances of"\r\n"
, and then instances of"\n"
.replace
– When used withnewline
as its first argument, this filter will replace instances of"\r\n"
, and then instances of"\n"
.split
– When used withnewline
, this filter will split by"\r\n"
when present, and then by"\n"
.
Technical note: Under the hood, each of these scenarios uses the regular expression /\r?\n/
.