diff --git a/_layouts/method.html b/_layouts/method.html deleted file mode 100644 index e11925b..0000000 --- a/_layouts/method.html +++ /dev/null @@ -1,11 +0,0 @@ ---- -layout: default ---- - -{{ content }} - -{% for item in page.examples %} - -{{ item }} - -{% endfor %} diff --git a/_sass/modules/_content-area.scss b/_sass/modules/_content-area.scss index 1b8c0f4..60694e3 100644 --- a/_sass/modules/_content-area.scss +++ b/_sass/modules/_content-area.scss @@ -21,7 +21,8 @@ box-sizing: border-box; } - & + .highlight { + // Label every second code block with "Output" + & + .highlight:nth-of-type(2n) { &:before { content: "Output"; } diff --git a/filters/append.md b/filters/append.md index 97f9e2e..80e438b 100644 --- a/filters/append.md +++ b/filters/append.md @@ -6,12 +6,12 @@ title: append ```liquid {% raw %} -{{ "/my/fancy/url" | append:".html" }} +{{ "/my/fancy/url" | append: ".html" }} {% endraw %} ``` ```text -/my/fancy/url.html +{{ "/my/fancy/url" | append: ".html" }} ``` `append` can also be used with variables: @@ -19,12 +19,11 @@ title: append ```liquid {% raw %} {% assign filename = "/index.html" %} -{{ product.url | append: filename }} +{{ "website.com" | append: filename }} {% endraw %} ``` -```liquid -{% raw %} -{{ product.url }}/index.html -{% endraw %} +```text +{% assign filename = "/index.html" %} +{{ "website.com" | append: filename }} ``` diff --git a/filters/ceil.md b/filters/ceil.md index 665e79a..1f07741 100644 --- a/filters/ceil.md +++ b/filters/ceil.md @@ -1,17 +1,35 @@ --- title: ceil -layout: method -examples: - - 1.2 --- -`ceil` rounds the input up to the nearest whole number. +`ceil` rounds the input up to the nearest whole number. The filter will attempt to cast any input to a number before it is applied. -| Input | Output | -|:-------------------------------------------|:-------| -| {% raw %}`{{ 1.2 | ceil }}` {% endraw %} | 2 | -| {% raw %}`{{ 1.7 | ceil }}` {% endraw %} | 2 | -| {% raw %}`{{ 2.0 | ceil }}` {% endraw %} | 2 | -| {% raw %}`{{ "18.3" | ceil }}`{% endraw %} | 19 | +```liquid +{% raw %} +{{ 1.2 | ceil }} +{% endraw %} +``` -It will attempt to cast any input to a number. +```text +2 +``` + +```liquid +{% raw %} +{{ 2.0 | ceil }} +{% endraw %} +``` + +```text +2 +``` + +```liquid +{% raw %} +{{ 183.357 | ceil }} +{% endraw %} +``` + +```text +184 +``` diff --git a/filters/date.md b/filters/date.md index 43c6f4a..cf64fcf 100644 --- a/filters/date.md +++ b/filters/date.md @@ -2,11 +2,24 @@ title: date --- -`date` converts a timestamp into another date format. +`date` converts a timestamp into another date format. The format for this syntax is the same as [`strftime`](//strftime.net). -| Input | Output | -|:--------------------------------------------------------------------------|:---------------------| -| {% raw %}`{{ article.published_at | date: "%a, %b %d, %y" }}`{% endraw %} | Tue, Apr 22, 14 | -| {% raw %}`{{ article.published_at | date: "%Y" }}`{% endraw %} | 2014 | +```liquid +{% raw %} +{{ article.published_at | date: "%a, %b %d, %y" }} +{% endraw %} +``` -The format for this syntax is the same as [`strftime`](http://strftime.net/). +```text +Fri, Jul 17, 15 +``` + +```liquid +{% raw %} +{{ article.published_at | date: "%Y" }} +{% endraw %} +``` + +```text +2015 +``` diff --git a/filters/default.md b/filters/default.md index 6963f26..a92055f 100644 --- a/filters/default.md +++ b/filters/default.md @@ -21,7 +21,7 @@ In this example, `product_price` is defined, so the default value is not used. ```liquid {% raw %} {% assign product_price = 4.99 %} -{{ product_price | default:2.99 }} +{{ product_price | default: 2.99 }} {% endraw %} ``` diff --git a/filters/divided_by.md b/filters/divided_by.md index 7c8e52c..ac1fb2a 100644 --- a/filters/divided_by.md +++ b/filters/divided_by.md @@ -2,11 +2,36 @@ title: divided_by --- -This filter divides its input by its argument. +`divided_by` divides its input (left side) by its argument (right side). It uses `to_number`, which converts to a decimal value unless already a numeric. -| Code | Output | -|:--------------------------------------------------|:-------| -| {% raw %}`{{ 4 | divided_by: 2 }}` {% endraw %} | 2 | -| {% raw %}`{{ "16" | divided_by: 4 }}`{% endraw %} | 4 | +The result is rounded down to the nearest integer (that is, the [floor](/filters/floor)). -It uses `to_number`, which converts to a decimal value unless already a numeric. +```liquid +{% raw %} +{{ 4 | divided_by: 2 }} +{% endraw %} +``` + +```text +{{ 4 | divided_by: 2 }} +``` + +```liquid +{% raw %} +{{ 16 | divided_by: 4 }} +{% endraw %} +``` + +```text +{{ 16 | divided_by: 4 }} +``` + +```liquid +{% raw %} +{{ 5 | divided_by: 3 }} +{% endraw %} +``` + +```text +{{ 5 | divided_by: 3 }} +``` diff --git a/filters/downcase.md b/filters/downcase.md index 91ce71c..bbb96a0 100644 --- a/filters/downcase.md +++ b/filters/downcase.md @@ -2,10 +2,24 @@ title: downcase --- -`downcase` makes each character in a string lowercase. +`downcase` makes each character in a string lowercase. It has no effect on strings which are already all lowercase. -| Code | Output | -|:-------------------------------------------------------|:-----------------| -| {% raw %}`{{ "Peter Parker" | downcase }}`{% endraw %} | `"peter parker"` | +```liquid +{% raw %} +{{ "Parker Moore" | downcase }} +{% endraw %} +``` -It doesn't modify strings which are already entirely lowercase. +```text +{{ "Parker Moore" | downcase }} +``` + +```liquid +{% raw %} +{{ "apple" | downcase }} +{% endraw %} +``` + +```text +{{ "apple" | downcase }} +``` diff --git a/filters/escape.md b/filters/escape.md index a9cfdd7..3a1bd38 100644 --- a/filters/escape.md +++ b/filters/escape.md @@ -2,11 +2,24 @@ title: escape --- -Escapes a string by replacing characters with escape sequences (so that the string can be used in a URI). +Escapes a string by replacing some characters with escape sequences (so that the string can be used in a URL, for example). It doesn't change strings that have nothing to escape. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ "Need tips? Ask a friend!" | escape }}`{% endraw %} | `"Need%20tips%3F%Ask%20a%20friend%21"` | -| {% raw %}`{{ "Nope" | escape }}`{% endraw %} | `"Nope"` | +```liquid +{% raw %} +{{ "Have you read 'James & the Giant Peach'?" | escape }} +{% endraw %} +``` -It doesn't modify strings that have nothing to escape. +```text +{{ "Have you read 'James & the Giant Peach'?" | escape }} +``` + +```liquid +{% raw %} +{{ "Tetsuro Takara" | escape }} +{% endraw %} +``` + +```text +{{ "Tetsuro Takara" | escape }} +``` diff --git a/filters/escape_once.md b/filters/escape_once.md index 02b02bc..4d8e7c0 100644 --- a/filters/escape_once.md +++ b/filters/escape_once.md @@ -2,12 +2,24 @@ title: escape_once --- -Escapes a string without affecting existing escaped entities. +Escapes a string without changing existing escaped entities. It doesn't change strings that have nothing to escape. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ "1 < 2 & 3" | escape_once }}`{% endraw %} | `"1 < 2 & 3"` | -| {% raw %}`{{ "<< Accept & Checkout" | escape_once }}`{% endraw %} | `"<< Accept & Checkout"` | -| {% raw %}`{{ "Nope" | escape_once }}`{% endraw %} | `"Nope"` | +```liquid +{% raw %} +{{ "1 < 2 & 3" | escape_once }} +{% endraw %} +``` -It doesn't modify strings that have nothing to escape. +```text +{{ "1 < 2 & 3" | escape_once }} +``` + +```liquid +{% raw %} +{{ "1 < 2 & 3" | escape_once }} +{% endraw %} +``` + +```text +{{ "1 < 2 & 3" | escape_once }} +``` diff --git a/filters/first.md b/filters/first.md index 11228b7..bc455d7 100644 --- a/filters/first.md +++ b/filters/first.md @@ -2,9 +2,32 @@ title: first --- -Returns the first element of an array. For example, if you have an array called `product.tags` that resolves to: `["sale", "mens", "womens", "awesome"]`: +`first` returns the first element of an array without sorting the array. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ product.tags | first }}`{% endraw %} | `"sale"` | +```liquid +{% raw %} +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} +{{ my_array.first }} +{% endraw %} +``` + +```text +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} + +{{ my_array.first }} +``` + +```liquid +{% raw %} +{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} + +{{ my_array.first }} +{% endraw %} +``` + +```text +{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} + +{{ my_array.first }} +``` diff --git a/filters/floor.md b/filters/floor.md index e8f2898..6ebb72f 100644 --- a/filters/floor.md +++ b/filters/floor.md @@ -4,11 +4,32 @@ title: floor `floor` rounds the input down to the nearest whole number. -| Input | Output | -|:-------------------------------------------|:-------| -| {% raw %}`{{ 1.2 | floor }}` {% endraw %} | 1 | -| {% raw %}`{{ 1.7 | floor }}` {% endraw %} | 1 | -| {% raw %}`{{ 2.0 | floor }}` {% endraw %} | 2 | -| {% raw %}`{{ "18.3" | floor }}`{% endraw %} | 18 | +```liquid +{% raw %} +{{ 1.2 | floor }} +{% endraw %} +``` -It will attempt to cast any input to a number. +```text +{{ 1.2 | floor }} +``` + +```liquid +{% raw %} +{{ 2.0 | floor }} +{% endraw %} +``` + +```text +{{ 2.0 | floor }} +``` + +```liquid +{% raw %} +{{ 183.357 | floor }} +{% endraw %} +``` + +```text +{{ 183.357 | floor }} +``` diff --git a/filters/join.md b/filters/join.md index e1035f3..567e982 100644 --- a/filters/join.md +++ b/filters/join.md @@ -2,10 +2,18 @@ title: join --- -`join` joins the elements of an array, using the character you provide. +`join` combines the elements of an array into a single string using the string you provide as a separator. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ product.tags | join: ', ' }}`{% endraw %} | `"sale, mens, womens, awesome` | +```liquid +{% raw %} +{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} -In the sample above, assume that `product.tags` resolves to: `["sale", "mens", "womens", "awesome"]`. +{{ beatles | join: " and " }} +{% endraw %} +``` + +```text +{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} + +{{ beatles | join: " and " }} +``` diff --git a/filters/last.md b/filters/last.md index 13d4a57..1ed8008 100644 --- a/filters/last.md +++ b/filters/last.md @@ -2,10 +2,32 @@ title: last --- -Return the last element of an array. +`last` returns the last element of an array without sorting the array. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ product.tags | last }}`{% endraw %} | `"awesome"` | +```liquid +{% raw %} +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} -In the sample above, assume that `product.tags` resolves to: `["sale", "mens", "womens", "awesome"]`. +{{ my_array.last }} +{% endraw %} +``` + +```text +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} + +{{ my_array.last }} +``` + +```liquid +{% raw %} +{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} + +{{ my_array.last }} +{% endraw %} +``` + +```text +{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} + +{{ my_array.last }} +``` diff --git a/filters/lstrip.md b/filters/lstrip.md index 80ca9ae..2ef7733 100644 --- a/filters/lstrip.md +++ b/filters/lstrip.md @@ -2,8 +2,14 @@ title: lstrip --- -Strips all whitespace (tabs, spaces, and newlines) from the left side of a string. +`lstrip` removes all whitespace (tabs, spaces, and newlines) from the left side of a string. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ ' too many spaces ' | lstrip }}`{% endraw %} | `"too many spaces "` | +```liquid +{% raw %} +{{ " So much room for activities! " | lstrip }} +{% endraw %} +``` + +```text +{{ " So much room for activities! " | lstrip }} +``` diff --git a/filters/minus.md b/filters/minus.md index c125690..0084c97 100644 --- a/filters/minus.md +++ b/filters/minus.md @@ -2,8 +2,34 @@ title: minus --- -Subtracts two numbers. +`minus` subtracts the number passed in from the input number. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 100 | minus: 10 }}`{% endraw %} | `90` | +```liquid +{% raw %} +{{ 4 | minus: 2 }} +{% endraw %} +``` + +```text +{{ 4 | minus: 2 }} +``` + +```liquid +{% raw %} +{{ 16 | minus: 4 }} +{% endraw %} +``` + +```text +{{ 16 | minus: 4 }} +``` + +```liquid +{% raw %} +{{ 183.357 | minus: 12 }} +{% endraw %} +``` + +```text +{{ 183.357 | minus: 12 }} +``` diff --git a/filters/modulo.md b/filters/modulo.md index 0d9b4e3..ace654a 100644 --- a/filters/modulo.md +++ b/filters/modulo.md @@ -2,8 +2,34 @@ title: modulo --- -Performs a modulo operation, i.e. returns the remainder. +`modulo` returns the remainder when the input is divided by the passed-in parameter. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 3 | modulo: 2 }}`{% endraw %} | `1` | +```liquid +{% raw %} +{{ 3 | modulo: 2 }} +{% endraw %} +``` + +```text +{{ 3 | modulo: 2 }} +``` + +```liquid +{% raw %} +{{ 24 | modulo: 7 }} +{% endraw %} +``` + +```text +{{ 24 | modulo: 7 }} +``` + +```liquid +{% raw %} +{{ 183.357 | modulo: 12 }} +{% endraw %} +``` + +```text +{{ 183.357 | modulo: 12 }} +``` diff --git a/filters/newline_to_br.md b/filters/newline_to_br.md index 3647640..6bba682 100644 --- a/filters/newline_to_br.md +++ b/filters/newline_to_br.md @@ -2,8 +2,24 @@ title: newline_to_br --- -Replace every newline (`n`) with an HTML break (`
`). +Replace every newline (`\n`) with an HTML line break (`
`). -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ "hello\nthere" | newline_to_br }}`{% endraw %} | `hello
there` | +```liquid +{% raw %} +{% capture string_with_newlines %} +Hello +there +{% endcapture %} + +{{ string_with_newlines | newline_to_br }} +{% endraw %} +``` + +```html +{% capture string_with_newlines %} +Hello +there +{% endcapture %} + +{{ string_with_newlines | newline_to_br }} +``` diff --git a/filters/plus.md b/filters/plus.md index 5e07e02..b2d121c 100644 --- a/filters/plus.md +++ b/filters/plus.md @@ -2,8 +2,34 @@ title: plus --- -Adds two numbers. +`plus` adds the number passed in to the input number. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 100 | plus: 10 }}`{% endraw %} | `110` | +```liquid +{% raw %} +{{ 4 | plus: 2 }} +{% endraw %} +``` + +```text +{{ 4 | plus: 2 }} +``` + +```liquid +{% raw %} +{{ 16 | plus: 4 }} +{% endraw %} +``` + +```text +{{ 16 | plus: 4 }} +``` + +```liquid +{% raw %} +{{ 183.357 | plus: 12 }} +{% endraw %} +``` + +```text +{{ 183.357 | plus: 12 }} +``` diff --git a/filters/prepend.md b/filters/prepend.md index 5b40fc5..19ed67d 100644 --- a/filters/prepend.md +++ b/filters/prepend.md @@ -2,8 +2,30 @@ title: prepend --- -Prepends a string onto another. +`prepend` adds a string to the beginning of the input string. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 'world' | prepend: 'hello ' }}`{% endraw %} | `hello world` | +```liquid +{% raw %} +{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }} +{% endraw %} +``` + +```text +{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }} +``` + +You can also `prepend` variables: + +```liquid +{% raw %} +{% assign url = "liquidmarkup.com" %} + +{{ "/index.html" | prepend: url }} +{% endraw %} +``` + +```text +{% assign url = "liquidmarkup.com" %} + +{{ "/index.html" | prepend: url }} +``` diff --git a/filters/remove.md b/filters/remove.md index 579243f..1bc5df7 100644 --- a/filters/remove.md +++ b/filters/remove.md @@ -2,8 +2,14 @@ title: remove --- -Removes every occurrence of a given string. +`remove` removes every occurrence of of the passed-in substring from the input string. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 'hello, hello world' | remove: 'hello' }}`{% endraw %} | `, world` | +```liquid +{% raw %} +{{ "I strained to see the train through the rain" | remove: "rain" }} +{% endraw %} +``` + +```text +{{ "I strained to see the train through the rain" | remove: "rain" }} +``` diff --git a/filters/remove_first.md b/filters/remove_first.md index 0377965..3e7c19d 100644 --- a/filters/remove_first.md +++ b/filters/remove_first.md @@ -2,8 +2,14 @@ title: remove_first --- -Removes the first occurrence of a given string. +`remove` removes the first occurrence of of the passed-in substring from the input string. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 'hello, hello world' | remove_first: 'hello' }}`{% endraw %} | `, hello world` | +```liquid +{% raw %} +{{ "I strained to see the train through the rain" | remove_first: "rain" }} +{% endraw %} +``` + +```text +{{ "I strained to see the train through the rain" | remove_first: "rain" }} +``` diff --git a/filters/replace.md b/filters/replace.md index 1fe088b..d8faf5c 100644 --- a/filters/replace.md +++ b/filters/replace.md @@ -2,8 +2,14 @@ title: replace --- -Replaces every occurrence of a given string. +`replace` replaces every occurrence of the first passed-in string in the input string with the second passed-in string. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 'hello, hello world' | replace: 'hello', 'goodbye' }}`{% endraw %} | `goodbye, goodbye world` | +```liquid +{% raw %} +{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }} +{% endraw %} +``` + +```text +{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }} +``` diff --git a/filters/replace_first.md b/filters/replace_first.md index a492a5b..babc555 100644 --- a/filters/replace_first.md +++ b/filters/replace_first.md @@ -2,8 +2,14 @@ title: replace_first --- -Replaces the first occurrence of a given string. +`replace_first` replaces the first occurrence of the first passed-in string in the input string with the second passed-in string. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 'hello, hello world' | replace_first: 'hello', 'goodbye' }}`{% endraw %} | `goodbye, hello world` | +```liquid +{% raw %} +{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }} +{% endraw %} +``` + +```text +{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }} +``` diff --git a/filters/reverse.md b/filters/reverse.md index baa3dbb..2fa939e 100644 --- a/filters/reverse.md +++ b/filters/reverse.md @@ -2,14 +2,30 @@ title: reverse --- -Reverses the order of an array. +`reverse` reverses the order of the items in an array. `reverse` cannot reverse a string. -{% highlight liquid %} +```liquid {% raw %} -{{ product.tags }} -// ['cool', 'sale', 'purple', 'awesome'] +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} -{{ product.tags | reverse }} -// ['awesome', 'purple', 'sale', 'cool'] +{{ my_array | reverse | join: ", " }} {% endraw %} -{% endhighlight %} +``` + +```text +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} + +{{ my_array | reverse | join: ", " }} +``` + +`reverse` cannot be used directly on a string, but you can split a string into an array, reverse the array, and rejoin it by chaining together filters: + +```liquid +{% raw %} +{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }} +{% endraw %} +``` + +```text +{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }} +``` diff --git a/filters/round.md b/filters/round.md index 86c4301..9b18b9c 100644 --- a/filters/round.md +++ b/filters/round.md @@ -2,11 +2,34 @@ title: round --- -Rounds the output to the nearest integer or specified number of decimals. +`round` rounds an input number to the nearest integer or, if a number is specified as a parameter, to that number of decimal places. -| Input | Output | -|:-------------------------------------------|:-------| -| {% raw %}`{{ 4.6 | round }}` {% endraw %} | 5 | -| {% raw %}`{{ 4.3 | round }}` {% endraw %} | 4 | -| {% raw %}`{{ 4.5612 | round: 2 }}` {% endraw %} | 4.56 | +```liquid +{% raw %} +{{ 1.2 | round }} +{% endraw %} +``` +```text +{{ 1.2 | round }} +``` + +```liquid +{% raw %} +{{ 2.7 | round }} +{% endraw %} +``` + +```text +{{ 2.7 | round }} +``` + +```liquid +{% raw %} +{{ 183.357 | round: 2 }} +{% endraw %} +``` + +```text +{{ 183.357 | round: 2 }} +``` diff --git a/filters/rstrip.md b/filters/rstrip.md index b5343d8..a0dd51c 100644 --- a/filters/rstrip.md +++ b/filters/rstrip.md @@ -2,8 +2,14 @@ title: rstrip --- -Strips all whitespace (tabs, spaces, and newlines) from the right side of a string. +`rstrip` removes all whitespace (tabs, spaces, and newlines) from the right side of a string. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ ' too many spaces ' | rstrip }}`{% endraw %} | `"too many spaces "` | +```liquid +{% raw %} +{{ " So much room for activities! " | rstrip }} +{% endraw %} +``` + +```text +{{ " So much room for activities! " | rstrip }} +``` diff --git a/filters/size.md b/filters/size.md index 7711f14..4efda90 100644 --- a/filters/size.md +++ b/filters/size.md @@ -2,20 +2,38 @@ title: size --- -

Returns the size of a string or an array.

+`size` returns the number of characters in a string or the number of items in an array. `size` can also be used with dot notation (for example, `{% raw %}{{ my_string.size }}{% endraw %}`). This allows you to use `size` inside other tags like conditionals. +```liquid +{% raw %} +{{ "Ground control to Major Tom." | size }} +{% endraw %} +``` -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 'is this a 30 character string?' | size }}`{% endraw %} | `30` | +```text +{{ "Ground control to Major Tom." | size }} +``` +```liquid +{% raw %} +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} -`size` can be used in dot notation, in cases where it needs to be used inside a tag. +{{ my_array | size }} +{% endraw %} +``` -
-{% highlight html %}{% raw %} -{% if collections.frontpage.products.size > 10 %} - There are more than 10 products in this collection! +```text +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} + +{{ my_array | size }} +``` + +Using dot notation: + +```liquid +{% raw %} +{% if site.pages.size > 10 %} + This is a big website! {% endif %} -{% endraw %}{% endhighlight %} -
+{% endraw %} +``` diff --git a/filters/slice.md b/filters/slice.md index 3fb7628..0b1ea0c 100644 --- a/filters/slice.md +++ b/filters/slice.md @@ -2,19 +2,48 @@ title: slice --- -The slice filter returns a substring, starting at the specified index. An optional second parameter can be passed to specify the length of the substring. If no second parameter is given, a substring of one character will be returned. +`slice` returns a substring of 1 character beginning at the index specified by the parameter passed in. An optional second parameter specifies the length of the substring to be returned. +String indices are numbered starting from 0. -| Input | Output | -|:------------------------------------------------|:-------| -| {% raw %}`{{ "hello" | slice: 0 }}`{% endraw %} | h | -| {% raw %}`{{ "hello" | slice: 1 }}`{% endraw %} | e | -| {% raw %}`{{ "hello" | slice: 1, 3 }}`{% endraw %} | ell | +```liquid +{% raw %} +{{ "Liquid" | slice: 0 }} +{% endraw %} +``` +```text +{{ "Liquid" | slice: 0 }} +``` -If the passed index is negative, it is counted from the end of the string. +```liquid +{% raw %} +{{ "Liquid" | slice: 2 }} +{% endraw %} +``` -| Input | Output | -|:------------------------------------------------|:-------| -| {% raw %}`{{ "hello" | slice: -3, 2 }}`{% endraw %} | ll | +```text +{{ "Liquid" | slice: 2 }} +``` +```liquid +{% raw %} +{{ "Liquid" | slice: 2, 5 }} +{% endraw %} +``` + +```text +{{ "Liquid" | slice: 2, 5 }} +``` + +If the first parameter is a negative number, the indices are counted from the end of the string: + +```liquid +{% raw %} +{{ "Liquid" | slice: -3, 2 }} +{% endraw %} +``` + +```text +{{ "Liquid" | slice: -3, 2 }} +``` diff --git a/filters/sort.md b/filters/sort.md index c6805f2..4c3c599 100644 --- a/filters/sort.md +++ b/filters/sort.md @@ -4,20 +4,16 @@ title: sort Sorts items in an array by a property of an item in the array. The order of the sorted array is case-sensitive. -

Input

-
-{% highlight html %}{% raw %} - -{% assign products = collection.products | sort: 'title' %} -{% for product in products %} - {{ product.title }} -{% endfor %}{% endraw %}{% endhighlight %} -
+```liquid +{% raw %} +{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} -

Output

-
-{% highlight html %}{% raw %} -A B a b -{% endraw %}{% endhighlight %} -
+{{ my_array | sort | join: ", " }} +{% endraw %} +``` +```text +{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} + +{{ my_array | sort | join: ", " }} +``` diff --git a/filters/split.md b/filters/split.md index 0aa4673..5a2a05b 100644 --- a/filters/split.md +++ b/filters/split.md @@ -2,22 +2,22 @@ title: split --- -The `split` filter takes on a substring as a parameter. The substring is used as a delimiter to divide a string into an array. You can output different parts of an array using [array filters](/themes/liquid-documentation/filters/array-filters). +`split` divides an input string into an array using the passed-in substring as a separator. `split` is commonly used to convert comma-separated items from a string to an array. -

Input

-{% highlight liquid %}{% raw %} -{% assign words = "Hi, how are you today?" | split: ' ' %} +```liquid +{% raw %} +{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} -{% for word in words %} -{{ word }} +{% for member in beatles %} + {{ member }} {% endfor %} -{% endraw %}{% endhighlight %} +{% endraw %} +``` -

Output

-{% highlight text %} -Hi, -how -are -you -today? -{% endhighlight %} +```text +{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} + +{% for member in beatles %} + {{ member }} +{% endfor %} +``` diff --git a/filters/strip.md b/filters/strip.md index 6c07f22..f580f4e 100644 --- a/filters/strip.md +++ b/filters/strip.md @@ -2,8 +2,14 @@ title: strip --- -Strips all whitespace (tabs, spaces, and newlines) from a string. +`strip` removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ ' too many spaces ' | strip }}`{% endraw %} | `"too many spaces"` | +```liquid +{% raw %} +{{ " So much room for activities! " | strip }} +{% endraw %} +``` + +```text +{{ " So much room for activities! " | strip }} +``` diff --git a/filters/strip_html.md b/filters/strip_html.md index 7def051..5d25703 100644 --- a/filters/strip_html.md +++ b/filters/strip_html.md @@ -2,10 +2,15 @@ title: strip_html --- -

Strips all HTML tags from a string.

+`strip_html` removes any HTML tags from a string. -

Input

-| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ "

Hello

World" | strip_html }}`{% endraw %} | `Hello World` | +```liquid +{% raw %} +{{ "Have you read James & the Giant Peach?" | strip_html }} +{% endraw %} +``` + +```text +{{ "Have you read James & the Giant Peach?" | strip_html }} +``` diff --git a/filters/strip_newlines.md b/filters/strip_newlines.md index 619eb73..88edabe 100644 --- a/filters/strip_newlines.md +++ b/filters/strip_newlines.md @@ -2,4 +2,25 @@ title: strip_newlines --- -Removes any line breaks/newlines from a string. +`strip_newlines` removes any newline characters (line breaks) from a string. + +```liquid +{% raw %} +{% capture string_with_newlines %} +Hello +there +{% endcapture %} + +{{ string_with_newlines | strip_newlines }} +{% endraw %} +``` + +```html +{% capture string_with_newlines %} +Hello +there +{% endcapture %} + +{{ string_with_newlines | strip_newlines }} +``` + diff --git a/filters/times.md b/filters/times.md index 407e030..f0065f6 100644 --- a/filters/times.md +++ b/filters/times.md @@ -2,8 +2,34 @@ title: times --- -Multiplies two numbers. +`times` multiplies its input by its argument. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 200 | times: 2 }}`{% endraw %} | `400` | +```liquid +{% raw %} +{{ 3 | times: 2 }} +{% endraw %} +``` + +```text +{{ 3 | times: 2 }} +``` + +```liquid +{% raw %} +{{ 24 | times: 7 }} +{% endraw %} +``` + +```text +{{ 24 | times: 7 }} +``` + +```liquid +{% raw %} +{{ 183.357 | times: 12 }} +{% endraw %} +``` + +```text +{{ 183.357 | times: 12 }} +``` diff --git a/filters/truncate.md b/filters/truncate.md index 60b307e..45f018d 100644 --- a/filters/truncate.md +++ b/filters/truncate.md @@ -2,9 +2,14 @@ title: truncate --- +`truncate` shortens a string down to the number of characters passed as a parameter. If the number of characters specified is less than the length of the string, an ellipsis (...) is appended to the string and is included in the character count. -

Truncates a string down to 'x' characters, where x is the number passed as a parameter. An ellipsis (...) is appended to the string and is included in the character count.

+```liquid +{% raw %} +{{ "Ground control to Major Tom." | truncate: 20 }} +{% endraw %} +``` -| Input | Output | -|:-------------------------------------------|:-------| -| {% raw %}`{{ "The cat came back the very next day" | truncate: 10 }}`{% endraw %} | "The cat..." | +```text +{{ "Ground control to Major Tom." | truncate: 20 }} +``` diff --git a/filters/truncatewords.md b/filters/truncatewords.md index 4747838..34888ce 100644 --- a/filters/truncatewords.md +++ b/filters/truncatewords.md @@ -2,9 +2,14 @@ title: truncatewords --- +`truncate` shortens a string down to the number of words passed as a parameter. If the number of words specified is less than the number of words in the string, an ellipsis (...) is appended to the string. -

Truncates a string down to 'x' words, where x is the number passed as a parameter. An ellipsis (...) is appended to the truncated string.

+```liquid +{% raw %} +{{ "Ground control to Major Tom." | truncatewords: 3 }} +{% endraw %} +``` -| Input | Output | -|:-------------------------------------------|:-------| -| {% raw %}`{{ "The cat came back the very next day" | truncatewords: 4 }}`{% endraw %} | The cat came back...| +```text +{{ "Ground control to Major Tom." | truncatewords: 3 }} +``` diff --git a/filters/uniq.md b/filters/uniq.md index 84b7703..0e97274 100644 --- a/filters/uniq.md +++ b/filters/uniq.md @@ -2,18 +2,18 @@ title: uniq --- +`uniq` removes any duplicate elements in an array. -

Removes any duplicate instances of an element in an array.

+```liquid +{% raw %} +{% assign my_array = "apples, oranges, bananas, oranges, apples" | split: ", " %} -

Input

-
{% highlight html %}{% raw %} -{% assign fruits = "orange apple banana apple orange" %} -{{ fruits | split: ' ' | uniq | join: ' ' }} -{% endraw %}{% endhighlight %}
- -

Output

-
{% highlight html%}{% raw %} -orange apple banana -{% endraw %}{% endhighlight %}
+{{ my_array | uniq | join: ", " }} +{% endraw %} +``` +```text +{% assign my_array = "apples, oranges, bananas, oranges, apples" | split: ", " %} +{{ my_array | uniq | join: ", " }} +``` diff --git a/filters/upcase.md b/filters/upcase.md index 1b50d88..5948ec6 100644 --- a/filters/upcase.md +++ b/filters/upcase.md @@ -2,10 +2,24 @@ title: upcase --- -

Converts a string into uppercase.

+`upcase` makes each character in a string uppercase. It has no effect on strings which are already all uppercase. +```liquid +{% raw %} +{{ "Parker Moore" | upcase }} +{% endraw %} +``` -| Input | Output | -|:-------------------------------------------|:-------| -| {% raw %}`{{ 'loud noises' | upcase }}`{% endraw %} | LOUD NOISES | +```text +{{ "Parker Moore" | upcase }} +``` +```liquid +{% raw %} +{{ "APPLE" | upcase }} +{% endraw %} +``` + +```text +{{ "APPLE" | upcase }} +``` diff --git a/filters/url_encode.md b/filters/url_encode.md index 989a795..d2bd93c 100644 --- a/filters/url_encode.md +++ b/filters/url_encode.md @@ -2,8 +2,24 @@ title: url_encode --- -Converts any URL-unsafe characters in a string into percent-encoded characters. +`url_encode` converts any URL-unsafe characters in a string into percent-encoded characters. -| Code | Output | -|:-------------------------------------------------------|:-------------------| -| {% raw %}`{{ 'john@liquid.com' | url_encode }}`{% endraw %} | `john%40liquid.com` | +```liquid +{% raw %} +{{ "john@liquid.com" | url_encode }} +{% endraw %} +``` + +```text +{{ "john@liquid.com" | url_encode }} +``` + +```liquid +{% raw %} +{{ "Tetsuro Takara" | url_encode }} +{% endraw %} +``` + +```text +{{ "Tetsuro Takara" | url_encode }} +``` diff --git a/tags/variable.md b/tags/variable.md index bfe36cc..1fad57b 100644 --- a/tags/variable.md +++ b/tags/variable.md @@ -2,126 +2,108 @@ title: Variable --- -Variable Tags are used to create new Liquid variables. +Variable tags create new Liquid variables. ## assign -

Creates a new variable.

+Creates a new variable. -
-{% highlight html %}{% raw %} +```liquid +{% raw %} {% assign my_variable = false %} {% if my_variable != true %} This statement is valid. {% endif %} -{% endraw %}{% endhighlight %} -
+{% endraw %} +``` -
-{% highlight html %}{% raw %} +```text This statement is valid. -{% endraw %}{% endhighlight %} -
+``` Use quotations ("") to save the variable as a string. -
-{% highlight html %}{% raw %} +```liquid +{% raw %} {% assign foo = "bar" %} {{ foo }} -{% endraw %}{% endhighlight %} -
+{% endraw %} +``` -
-{% highlight html %}{% raw %} +```text bar -{% endraw %}{% endhighlight %} -
+``` ## capture -

Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created through {% capture %} are strings.

+Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created through `{% raw %}{% capture %}{% endraw %}` are strings. -
-{% highlight html %}{% raw %} +```liquid +{% raw %} {% capture my_variable %}I am being captured.{% endcapture %} {{ my_variable }} -{% endraw %}{% endhighlight %} -
+{% endraw %} +``` -
-{% highlight html %}{% raw %} +```text I am being captured. -{% endraw %}{% endhighlight %} -
+``` ## increment -Creates a new number variable, and increases its value by one every time it is called. The initial value is 0. +Creates a new number variable, and increases its value by one every time it is called. The initial value is 0. -
-{% highlight html %}{% raw %} +```liquid +{% raw %} {% increment variable %} {% increment variable %} {% increment variable %} -{% endraw %}{% endhighlight %} -
+{% endraw %} +``` -
-{% highlight html %}{% raw %} +```text 0 1 2 -{% endraw %}{% endhighlight %} -
+``` -Variables created through the increment tag are independent from variables created through assign or capture. +Variables created through the `increment` tag are independent from variables created through `assign` or `capture`. -In the example below, a variable named "var" is created through assign. The increment tag is then used several times on a variable with the same name. However, note that the increment tag does not affect the value of "var" that was created through assign. +In the example below, a variable named "var" is created through `assign`. The `increment` tag is then used several times on a variable with the same name. However, note that the `increment` tag does not affect the value of "var" that was created through `assign`. -
-{% highlight html %}{% raw %} +```liquid +{% raw %} {% assign var = 10 %} {% increment var %} {% increment var %} {% increment var %} {{ var }} -{% endraw %}{% endhighlight %} -
+{% endraw %} +``` -
-{% highlight html %}{% raw %} +```text 0 1 2 -10 -{% endraw %}{% endhighlight %} -
- +10 +``` ## decrement -Creates a new number variable, and decreases its value by one every time it is called. The initial value is -1. +Creates a new number variable, and decreases its value by one every time it is called. The initial value is -1. -
-{% highlight html %}{% raw %} +```liquid +{% raw %} {% decrement variable %} {% decrement variable %} {% decrement variable %} -{% endraw %}{% endhighlight %} -
+{% endraw %} +``` -
-{% highlight html %}{% raw %} +```text -1 -2 -3 -{% endraw %}{% endhighlight %} -
- -Like increment, variables declared inside decrement are independent from variables created through assign or capture. - - - - +``` +Like [increment](#increment), variables declared inside `decrement` are independent from variables created through `assign` or `capture`.