diff --git a/_basics/introduction.md b/_basics/introduction.md index cdf3fd48e..051a6ba80 100644 --- a/_basics/introduction.md +++ b/_basics/introduction.md @@ -80,3 +80,12 @@ Multiple filters can be used on one output, and are applied from left to right. ```text {{ "adam!" | capitalize | prepend: "Hello " }} ``` + +Filters can be categorized into various types: + +- Array filters +- Math filters +- String filters +- Other filters + +You can see the list of filters for each type in their respective sections on the side menu. diff --git a/_basics/whitespace.md b/_basics/whitespace.md index 6059f756a..4dedff8bb 100644 --- a/_basics/whitespace.md +++ b/_basics/whitespace.md @@ -39,6 +39,8 @@ By including a hyphen in your `assign` closing delimiter, you can strip the whit {{ my_variable }} ``` +## Avoiding whitespace using hyphens + If you don't want any of your tags to print whitespace, as a general rule you can add hyphens to both sides of all your tags (`{% raw %}{%-{% endraw %}` and `{% raw %}-%}{% endraw %}`):
Input
@@ -84,3 +86,24 @@ If you don't want any of your tags to print whitespace, as a general rule you ca Hello there! {%- endif %} ``` + +## Avoiding whitespace without hyphens {%- include version-badge.html version="5.0.0" %} + +If you use the [`liquid`]({{ '/tags/template#liquid' | prepend: site.baseurl }}) tag with the `echo` keyword, you can avoid whitespace without adding hyphens throughout the Liquid code: + +```liquid +{%- raw -%} +{% liquid +assign username = "John G. Chalmers-Smith" +if username and username.size > 10 + echo "Wow, " | append: username | append: ", you have a long name!" +else + echo "Hello there!" +endif +%} +{% endraw %} +``` + +## Note about the Liquid docs + +In the rest of the documentation, some example output text may exclude whitespace even if the corresponding input Liquid code doesn't have any hyphens. The example output is for illustrating the effects of a given tag or filter only. It shouldn't be treated as a precise output of the given input code. diff --git a/_filters/abs.md b/_filters/abs.md index 6763ecc23..72e38a5fd 100644 --- a/_filters/abs.md +++ b/_filters/abs.md @@ -1,16 +1,17 @@ --- title: abs +category: math description: Liquid filter that returns the absolute value of a number. -redirect_from: /filters/ --- -Returns the absolute value of a number. +Returns the absolute value of a number. `abs` will also work on a string that only contains a number.Input
```liquid {%- raw -%} {{ -17 | abs }} {{ 4 | abs }} +{{ "-19.86" | abs }} {% endraw %} ``` @@ -18,18 +19,5 @@ Returns the absolute value of a number. ```text {{ -17 | abs }} {{ 4 | abs }} -``` - -`abs` will also work on a string that only contains a number. - -Input
-```liquid -{%- raw -%} -{{ "-19.86" | abs }} -{% endraw %} -``` - -Output
-```text {{ "-19.86" | abs }} ``` diff --git a/_filters/append.md b/_filters/append.md index ab8356c9d..efb79d200 100644 --- a/_filters/append.md +++ b/_filters/append.md @@ -1,34 +1,21 @@ --- title: append +category: string description: Liquid filter that appends a string to another string. --- -Adds the specified string to the end of another string. +Adds the specified string to the end of another string. `append` can also accept a variable as its argument.Input
```liquid {%- raw -%} {{ "/my/fancy/url" | append: ".html" }} +{% assign filename = "/index.html" %} {{ "website.com" | append: filename }} {% endraw %} ```Output
```text {{ "/my/fancy/url" | append: ".html" }} -``` - -`append` can also accept a variable as its argument. - -Input
-```liquid -{%- raw -%} -{% assign filename = "/index.html" %} -{{ "website.com" | append: filename }} -{% endraw %} -``` - -Output
-```text -{% assign filename = "/index.html" %} -{{ "website.com" | append: filename }} +{% assign filename = "/index.html" -%} {{ "website.com" | append: filename }} ``` diff --git a/_filters/at_least.md b/_filters/at_least.md index 3f23b706c..3b0a9faea 100644 --- a/_filters/at_least.md +++ b/_filters/at_least.md @@ -1,5 +1,6 @@ --- title: at_least +category: math description: Liquid filter that limits a number to a minimum value. version-badge: 4.0.1 --- @@ -16,6 +17,6 @@ Limits a number to a minimum value.Output
```text -5 -4 +{{ 4 | at_least: 5 }} +{{ 4 | at_least: 3 }} ``` diff --git a/_filters/at_most.md b/_filters/at_most.md index 728e7960a..6a083ab03 100644 --- a/_filters/at_most.md +++ b/_filters/at_most.md @@ -1,5 +1,6 @@ --- title: at_most +category: math description: Liquid filter that limits a number to a maximum value. version-badge: 4.0.1 --- @@ -16,6 +17,6 @@ Limits a number to a maximum value.Output
```text -4 -3 +{{ 4 | at_most: 5 }} +{{ 4 | at_most: 3 }} ``` diff --git a/_filters/capitalize.md b/_filters/capitalize.md index 99475e379..63683df8f 100644 --- a/_filters/capitalize.md +++ b/_filters/capitalize.md @@ -1,5 +1,6 @@ --- title: capitalize +category: string description: Liquid filter that capitalizes the first character of a string and downcases the remaining characters. --- @@ -9,24 +10,12 @@ Makes the first character of a string capitalized and converts the remaining cha ```liquid {%- raw -%} {{ "title" | capitalize }} -{% endraw %} -``` - -Output
-```text -{{ "title" | capitalize }} -``` - -Only the first character of a string is capitalized, so later words are not capitalized: - -Input
-```liquid -{%- raw -%} {{ "my GREAT title" | capitalize }} {% endraw %} ```Output
```text +{{ "title" | capitalize }} {{ "my GREAT title" | capitalize }} ``` diff --git a/_filters/ceil.md b/_filters/ceil.md index 80c67f3e0..1a81d6d3e 100644 --- a/_filters/ceil.md +++ b/_filters/ceil.md @@ -1,9 +1,10 @@ --- title: ceil +category: math description: Liquid filter that returns the ceiling of a number by rounding up to the nearest integer. --- -Rounds an input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied. +Rounds an input up to the nearest whole number. `ceil` will also work on a string that only contains a number.Input
```liquid @@ -11,6 +12,7 @@ Rounds an input up to the nearest whole number. Liquid tries to convert the inpu {{ 1.2 | ceil }} {{ 2.0 | ceil }} {{ 183.357 | ceil }} +{{ "3.5" | ceil }} {% endraw %} ``` @@ -19,18 +21,5 @@ Rounds an input up to the nearest whole number. Liquid tries to convert the inpu {{ 1.2 | ceil }} {{ 2.0 | ceil }} {{ 183.357 | ceil }} -``` - -Here the input value is a string: - -Input
-```liquid -{%- raw -%} -{{ "3.5" | ceil }} -{% endraw %} -``` - -Output
-```text {{ "3.5" | ceil }} ``` diff --git a/_filters/compact.md b/_filters/compact.md index 174339f42..bad7c5b72 100644 --- a/_filters/compact.md +++ b/_filters/compact.md @@ -1,5 +1,6 @@ --- title: compact +category: array description: Liquid filter that removes nil values from an array. version-badge: 4.0.0 --- diff --git a/_filters/concat.md b/_filters/concat.md index 7ce565ad1..6c2fef36d 100644 --- a/_filters/concat.md +++ b/_filters/concat.md @@ -1,5 +1,6 @@ --- title: concat +category: array description: Liquid filter that concatenates arrays. version-badge: 4.0.0 --- diff --git a/_filters/date.md b/_filters/date.md index cc0b79f18..683928020 100644 --- a/_filters/date.md +++ b/_filters/date.md @@ -1,60 +1,31 @@ --- title: date +category: aaa description: Liquid filter that prints and formats dates. +redirect_from: /filters/ --- Converts a timestamp into another date format. The format for this syntax is the same as [`strftime`](http://strftime.net). The input uses the same format as Ruby's [`Time.parse`](https://ruby-doc.org/stdlib/libdoc/time/rdoc/Time.html#method-c-parse). -Input
-```liquid -{%- raw -%} -{{ article.published_at | date: "%a, %b %d, %y" }} -{% endraw %} -``` - -Output
-```text -Fri, Jul 17, 15 -``` - -Input
-```liquid -{%- raw -%} -{{ article.published_at | date: "%Y" }} -{% endraw %} -``` - -Output
-```text -2015 -``` - `date` works on strings if they contain well-formatted dates. - -Input
-```liquid -{%- raw -%} -{{ "March 14, 2016" | date: "%b %d, %y" }} -{% endraw %} -``` - -Output
-```text -{{ "March 14, 2016" | date: "%b %d, %y" }} -``` - To get the current time, pass the special word `"now"` (or `"today"`) to `date`.Input
```liquid {%- raw -%} +{{ article.published_at | date: "%a, %b %d, %y" }} +{{ article.published_at | date: "%Y" }} +{{ "March 14, 2016" | date: "%b %d, %y" }} This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}. {% endraw %} ```Output
```text +Fri, Jul 17, 15 +2015 +{{ "March 14, 2016" | date: "%b %d, %y" }} This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}. ``` -Note that the value will be the current time of when the page was last generated from the template, not when the page is presented to a user if caching or static site generation is involved. +Note: If caching or static site generation is involved, the value will be the moment when the page was last generated from the template, not when the page is presented to a user. diff --git a/_filters/default.md b/_filters/default.md index 9231b85b1..c8a4f08e1 100644 --- a/_filters/default.md +++ b/_filters/default.md @@ -1,54 +1,30 @@ --- title: default +category: aaa description: Liquid filter that specifies a fallback in case a value doesn't exist. --- Sets a default value for any variable with no assigned value. `default` will show its value if the input is `nil`, `false`, or empty. -In this example, `product_price` is not defined, so the default value is used. +In the following examples with a variable `product_price`: +* When it's not defined, the default value is used. +* When it's defined, the default value is not used. +* When it's empty, so the default value is used.Input
```liquid {%- raw -%} {{ product_price | default: 2.99 }} +{% assign product_price = 4.99 %} {{ product_price | default: 2.99 }} +{% assign product_price = "" %} {{ product_price | default: 2.99 }} {% endraw %} ```Output
```text {{ product_price | default: 2.99 }} -``` - -In this example, `product_price` is defined, so the default value is not used. - -Input
-```liquid -{%- raw -%} -{% assign product_price = 4.99 %} -{{ product_price | default: 2.99 }} -{% endraw %} -``` - -Output
-```text -{% assign product_price = 4.99 %} -{{ product_price | default: 2.99 }} -``` - -In this example, `product_price` is empty, so the default value is used. - -Input
-```liquid -{%- raw -%} -{% assign product_price = "" %} -{{ product_price | default: 2.99 }} -{% endraw %} -``` - -Output
-```text -{% assign product_price = "" %} -{{ product_price | default: 2.99 }} +{% assign product_price = 4.99 -%} {{ product_price | default: 2.99 }} +{% assign product_price = "" -%} {{ product_price | default: 2.99 }} ``` ### Allowing `false` {%- include version-badge.html version="5.0.0" %} @@ -65,6 +41,5 @@ To allow variables to return `false` instead of the default value, you can use tOutput
```text - false ``` diff --git a/_filters/divided_by.md b/_filters/divided_by.md index 72c83db54..f6ab5041f 100644 --- a/_filters/divided_by.md +++ b/_filters/divided_by.md @@ -1,5 +1,6 @@ --- title: divided_by +category: math description: Liquid filter that divides a number by another number. --- @@ -25,60 +26,30 @@ The result is rounded down to the nearest integer (that is, the [floor]({{ "/fil `divided_by` produces a result of the same type as the divisor — that is, if you divide by an integer, the result will be an integer. If you divide by a float (a number with a decimal in it), the result will be a float. -For example, here the divisor is an integer: -Input
```liquid {%- raw -%} {{ 20 | divided_by: 7 }} -{% endraw %} -``` - -Output
-```text -{{ 20 | divided_by: 7 }} -``` - -Here it is a float: - -Input
-```liquid -{%- raw -%} {{ 20 | divided_by: 7.0 }} {% endraw %} ```Output
```text +{{ 20 | divided_by: 7 }} {{ 20 | divided_by: 7.0 }} ``` ### Changing variable types -You might want to use a variable as a divisor, in which case you can't simply add `.0` to convert it to a float. In these cases, you can `assign` a version of your variable converted to a float using the `times` filter. +You might want to use a variable as a divisor, in which case you can't simply add `.0` to convert it to a float. In these cases, you can `assign` a version of your variable converted to a float using the `times` filter to [multiply]({{ "/filters/times/" | prepend: site.baseurl }}) the variable by `1.0`. -In this example, we're dividing by a variable that contains an integer, so we get an integer: +In this example, when we divide by a variable that contains an integer, we get an integer result. When we convert the variable to float and divide by the float instead, we get a float result.Input
```liquid {%- raw -%} -{% assign my_integer = 7 %} -{{ 20 | divided_by: my_integer }} -{% endraw %} -``` - -Output
-```text -{% assign my_integer = 7 %} -{{ 20 | divided_by: my_integer }} -``` - -Here, we [multiply]({{ "/filters/times/" | prepend: site.baseurl }}) the variable by `1.0` to get a float, then divide by the float instead: - -Input
-```liquid -{%- raw -%} -{% assign my_integer = 7 %} +{% assign my_integer = 7 %} {{ 20 | divided_by: my_integer }} {% assign my_float = my_integer | times: 1.0 %} {{ 20 | divided_by: my_float }} {% endraw %} @@ -86,7 +57,8 @@ Here, we [multiply]({{ "/filters/times/" | prepend: site.baseurl }}) the variablOutput
```text -{% assign my_integer = 7 %} -{% assign my_float = my_integer | times: 1.0 %} +{% assign my_integer = 7 -%} +{{ 20 | divided_by: my_integer }} +{% assign my_float = my_integer | times: 1.0 -%} {{ 20 | divided_by: my_float }} ``` diff --git a/_filters/downcase.md b/_filters/downcase.md index e73212767..36fd783ff 100644 --- a/_filters/downcase.md +++ b/_filters/downcase.md @@ -1,5 +1,6 @@ --- title: downcase +category: string description: Liquid filter that converts a string to lowercase. --- @@ -9,22 +10,12 @@ Makes each character in a string lowercase. It has no effect on strings which ar ```liquid {%- raw -%} {{ "Parker Moore" | downcase }} -{% endraw %} -``` - -Output
-```text -{{ "Parker Moore" | downcase }} -``` - -Input
-```liquid -{%- raw -%} {{ "apple" | downcase }} {% endraw %} ```Output
```text +{{ "Parker Moore" | downcase }} {{ "apple" | downcase }} ``` diff --git a/_filters/escape.md b/_filters/escape.md index 1a7db6119..c0529ca21 100644 --- a/_filters/escape.md +++ b/_filters/escape.md @@ -1,5 +1,6 @@ --- title: escape +category: aaa description: Liquid filter that escapes URL-unsafe characters in a string. --- @@ -9,22 +10,12 @@ Escapes a string by replacing characters with escape sequences (so that the stri ```liquid {%- raw -%} {{ "Have you read 'James & the Giant Peach'?" | escape }} -{% endraw %} -``` - -Output
-```text -{{ "Have you read 'James & the Giant Peach'?" | escape }} -``` - -Input
-```liquid -{%- raw -%} {{ "Tetsuro Takara" | escape }} {% endraw %} ```Output
```text +{{ "Have you read 'James & the Giant Peach'?" | escape }} {{ "Tetsuro Takara" | escape }} ``` diff --git a/_filters/escape_once.md b/_filters/escape_once.md index 1aa358b24..5d0f8917f 100644 --- a/_filters/escape_once.md +++ b/_filters/escape_once.md @@ -1,30 +1,23 @@ --- title: escape_once +category: aaa description: Liquid filter that escapes URL-unsafe characters in a string once. --- -Escapes a string without changing existing escaped entities. It doesn't change strings that don't have anything to escape. +Escapes a string without changing existing escaped entities. Notice the difference between `escape` and `escape_once` in their output:Input
```liquid {%- raw -%} {{ "1 < 2 & 3" | escape_once }} -{% endraw %} -``` - -Output
-```text -{{ "1 < 2 & 3" | escape_once }} -``` - -Input
-```liquid -{%- raw -%} +{{ "1 < 2 & 3" | escape }} {{ "1 < 2 & 3" | escape_once }} {% endraw %} ```Output
```text +{{ "1 < 2 & 3" | escape_once }} +{{ "1 < 2 & 3" | escape }} {{ "1 < 2 & 3" | escape_once }} ``` diff --git a/_filters/first.md b/_filters/first.md index 386975da9..e989fed96 100644 --- a/_filters/first.md +++ b/_filters/first.md @@ -1,5 +1,6 @@ --- title: first +category: array description: Liquid filter that returns the first item of an array. --- @@ -9,27 +10,17 @@ Returns the first item of an array. ```liquid {%- raw -%} {{ "Ground control to Major Tom." | split: " " | first }} -{% endraw %} -``` - -Output
-```text -{{ "Ground control to Major Tom." | split: " " | first }} -``` -Input
-```liquid -{%- raw -%} {% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} - {{ my_array.first }} {% endraw %} ```Output
```text -{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} +{{ "Ground control to Major Tom." | split: " " | first }} +{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " -%} {{ my_array.first }} ``` diff --git a/_filters/floor.md b/_filters/floor.md index 70ea9c9b1..ece193228 100644 --- a/_filters/floor.md +++ b/_filters/floor.md @@ -1,9 +1,10 @@ --- title: floor +category: math description: Liquid filter that returns the floor of a number by rounding down to the nearest integer. --- -Rounds an input down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied. +Rounds an input down to the nearest whole number. `floor` will also work on a string that only contains a number.Input
```liquid @@ -11,6 +12,7 @@ Rounds an input down to the nearest whole number. Liquid tries to convert the in {{ 1.2 | floor }} {{ 2.0 | floor }} {{ 183.357 | floor }} +{{ "3.5" | floor }} {% endraw %} ``` @@ -19,18 +21,5 @@ Rounds an input down to the nearest whole number. Liquid tries to convert the in {{ 1.2 | floor }} {{ 2.0 | floor }} {{ 183.357 | floor }} -``` - -Here the input value is a string: - -Input
-```liquid -{%- raw -%} -{{ "3.5" | floor }} -{% endraw %} -``` - -Output
-```text {{ "3.5" | floor }} ``` diff --git a/_filters/join.md b/_filters/join.md index 1e3391bce..e2ce3c585 100644 --- a/_filters/join.md +++ b/_filters/join.md @@ -1,5 +1,6 @@ --- title: join +category: array description: Liquid filter that joins an array of strings into a single string. --- @@ -16,7 +17,7 @@ Combines the items in an array into a single string using the argument as a sepaOutput
```text -{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} +{% assign beatles = "John, Paul, George, Ringo" | split: ", " -%} {{ beatles | join: " and " }} ``` diff --git a/_filters/last.md b/_filters/last.md index 7d3c911f1..7d64c52a8 100644 --- a/_filters/last.md +++ b/_filters/last.md @@ -1,5 +1,6 @@ --- title: last +category: array description: Liquid filter that returns the last item of an array. --- @@ -9,27 +10,17 @@ Returns the last item of an array. ```liquid {%- raw -%} {{ "Ground control to Major Tom." | split: " " | last }} -{% endraw %} -``` - -Output
-```text -{{ "Ground control to Major Tom." | split: " " | last }} -``` -Input
-```liquid -{%- raw -%} {% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} - {{ my_array.last }} {% endraw %} ```Output
```text -{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} +{{ "Ground control to Major Tom." | split: " " | last }} +{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " -%} {{ my_array.last }} ``` diff --git a/_filters/lstrip.md b/_filters/lstrip.md index df7ec6ead..01d9a062c 100644 --- a/_filters/lstrip.md +++ b/_filters/lstrip.md @@ -1,5 +1,6 @@ --- title: lstrip +category: string description: Liquid filter that removes all whitespace from the left side of a string. --- diff --git a/_filters/map.md b/_filters/map.md index 62e754d83..e5570a3c7 100644 --- a/_filters/map.md +++ b/_filters/map.md @@ -1,5 +1,6 @@ --- title: map +category: array description: Liquid filter that creates an array of values by extracting a named property from an object. --- diff --git a/_filters/minus.md b/_filters/minus.md index 53232939a..9366a8df0 100644 --- a/_filters/minus.md +++ b/_filters/minus.md @@ -1,5 +1,6 @@ --- title: minus +category: math description: Liquid filter that subtracts one number from another number. --- diff --git a/_filters/modulo.md b/_filters/modulo.md index b0de01a02..6077b1af0 100644 --- a/_filters/modulo.md +++ b/_filters/modulo.md @@ -1,5 +1,6 @@ --- title: modulo +category: math description: Liquid filter that returns the remainder of a division operation. --- diff --git a/_filters/newline_to_br.md b/_filters/newline_to_br.md index 70b197451..8a1a6f10d 100644 --- a/_filters/newline_to_br.md +++ b/_filters/newline_to_br.md @@ -1,5 +1,6 @@ --- title: newline_to_br +category: string description: Liquid filter that converts newlines in a string to HTMLInput
```liquid {%- raw -%} {{ "apples, oranges, and bananas" | prepend: "Some fruit: " }} +{% assign url = "example.com" %} {{ "/index.html" | prepend: url }} {% endraw %} ```Output
```text {{ "apples, oranges, and bananas" | prepend: "Some fruit: " }} -``` - -`prepend` can also accept a variable as its argument. - -Input
-```liquid -{%- raw -%} -{% assign url = "example.com" %} -{{ "/index.html" | prepend: url }} -{% endraw %} -``` - -Output
-```text -{% assign url = "example.com" %} -{{ "/index.html" | prepend: url }} +{% assign url = "example.com" -%} {{ "/index.html" | prepend: url }} ``` diff --git a/_filters/remove.md b/_filters/remove.md index 8349b0b6e..a92ab82df 100644 --- a/_filters/remove.md +++ b/_filters/remove.md @@ -1,5 +1,6 @@ --- title: remove +category: string description: Liquid filter that removes all occurences of a given substring from a string. --- diff --git a/_filters/remove_first.md b/_filters/remove_first.md index 4c659171f..bae506725 100644 --- a/_filters/remove_first.md +++ b/_filters/remove_first.md @@ -1,5 +1,6 @@ --- title: remove_first +category: string description: Liquid filter that removes the first occurence of a given substring from a string. --- diff --git a/_filters/replace.md b/_filters/replace.md index 3fde134b6..82827f6da 100644 --- a/_filters/replace.md +++ b/_filters/replace.md @@ -1,5 +1,6 @@ --- title: replace +category: string description: Liquid filter that replaces all occurences of a given substring in a string. --- diff --git a/_filters/replace_first.md b/_filters/replace_first.md index 5c46ac431..5a9781ad7 100644 --- a/_filters/replace_first.md +++ b/_filters/replace_first.md @@ -1,5 +1,6 @@ --- title: replace_first +category: string description: Liquid filter that replaces the first occurrence of a given substring in a string. --- diff --git a/_filters/reverse.md b/_filters/reverse.md index b7d88bc68..7e8edb3df 100644 --- a/_filters/reverse.md +++ b/_filters/reverse.md @@ -1,5 +1,6 @@ --- title: reverse +category: array description: Liquid filter that reverses an array, or a string converted to an array. --- @@ -16,7 +17,7 @@ Reverses the order of the items in an array. `reverse` cannot reverse a string.Output
```text -{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " -%} {{ my_array | reverse | join: ", " }} ``` diff --git a/_filters/round.md b/_filters/round.md index 6eb2e655a..a81ea8769 100644 --- a/_filters/round.md +++ b/_filters/round.md @@ -1,5 +1,6 @@ --- title: round +category: math description: Liquid filter that rounds a number to the nearest integer. --- diff --git a/_filters/rstrip.md b/_filters/rstrip.md index 5226dd977..b037d4ac9 100644 --- a/_filters/rstrip.md +++ b/_filters/rstrip.md @@ -1,5 +1,6 @@ --- title: rstrip +category: string description: Liquid filter that removes all whitespace from the right side of a string. --- diff --git a/_filters/size.md b/_filters/size.md index 4d50dfc58..5780fe106 100644 --- a/_filters/size.md +++ b/_filters/size.md @@ -1,5 +1,6 @@ --- title: size +category: array description: Liquid filter that returns the number of characters in a string or the number of items in an array. --- @@ -9,27 +10,17 @@ Returns the number of characters in a string or the number of items in an array. ```liquid {%- raw -%} {{ "Ground control to Major Tom." | size }} -{% endraw %} -``` - -Output
-```text -{{ "Ground control to Major Tom." | size }} -``` -Input
-```liquid -{%- raw -%} {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} - {{ my_array.size }} {% endraw %} ```Output
```text -{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} +{{ "Ground control to Major Tom." | size }} +{% assign my_array = "apples, oranges, peaches, plums" | split: ", " -%} {{ my_array.size }} ``` diff --git a/_filters/slice.md b/_filters/slice.md index 2f6c70482..4ce55d552 100644 --- a/_filters/slice.md +++ b/_filters/slice.md @@ -1,49 +1,32 @@ --- title: slice +category: string description: Liquid filter that returns a substring or item from a given position in a string or array. --- Returns a substring of one character or series of array items beginning at the index specified by the first argument. An optional second argument specifies the length of the substring or number of array items to be returned. -String or array indices are numbered starting from 0. +String or array indices are numbered starting from `0`. If the first argument is a negative number, the indices are counted from the end of the string.Input
```liquid {%- raw -%} {{ "Liquid" | slice: 0 }} -{% endraw %} -``` - -Output
-```text -{{ "Liquid" | slice: 0 }} -``` - -Input
-```liquid -{%- raw -%} -{{ "Liquid" | slice: 2 }} -{% endraw %} -``` - -Output
-```text {{ "Liquid" | slice: 2 }} -``` - -Input
-```liquid -{%- raw -%} {{ "Liquid" | slice: 2, 5 }} +{{ "Liquid" | slice: -3, 2 }} {% endraw %} ```Output
```text +{{ "Liquid" | slice: 0 }} +{{ "Liquid" | slice: 2 }} {{ "Liquid" | slice: 2, 5 }} +{{ "Liquid" | slice: -3, 2 }} ``` -Here the input value is an array: +When the input value is an array, the matching items are concatenated and returned:Input
```liquid @@ -55,20 +38,6 @@ Here the input value is an array:Output
```text -{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} +{% assign beatles = "John, Paul, George, Ringo" | split: ", " -%} {{ beatles | slice: 1, 2 }} ``` - -If the first argument is a negative number, the indices are counted from the end of the string. - -Input
-```liquid -{%- raw -%} -{{ "Liquid" | slice: -3, 2 }} -{% endraw %} -``` - -Output
-```text -{{ "Liquid" | slice: -3, 2 }} -``` diff --git a/_filters/sort.md b/_filters/sort.md index 72f0a9998..24b23faf5 100644 --- a/_filters/sort.md +++ b/_filters/sort.md @@ -1,5 +1,6 @@ --- title: sort +category: array description: Liquid filter that sorts an array in case-sensitive order. --- @@ -16,7 +17,7 @@ Sorts items in an array in case-sensitive order.Output
```text -{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} +{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " -%} {{ my_array | sort | join: ", " }} ``` diff --git a/_filters/sort_natural.md b/_filters/sort_natural.md index 233efc01f..b1c741fdc 100644 --- a/_filters/sort_natural.md +++ b/_filters/sort_natural.md @@ -1,5 +1,6 @@ --- title: sort_natural +category: array description: Liquid filter that sorts an array in case-insensitive order. version-badge: 4.0.0 --- @@ -17,7 +18,7 @@ Sorts items in an array in case-insensitive order.Output
```text -{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} +{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " -%} {{ my_array | sort_natural | join: ", " }} ``` diff --git a/_filters/split.md b/_filters/split.md index c7e8ee463..80c861616 100644 --- a/_filters/split.md +++ b/_filters/split.md @@ -1,5 +1,6 @@ --- title: split +category: array description: Liquid filter that splits a string into an array using separators. --- @@ -11,16 +12,16 @@ Divides a string into an array using the argument as a separator. `split` is com {% assign beatles = "John, Paul, George, Ringo" | split: ", " %} {% for member in beatles %} - {{ member }} +- {{ member }} {% endfor %} {% endraw %} ```Output
```text -{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} +{% assign beatles = "John, Paul, George, Ringo" | split: ", " -%} -{% for member in beatles %} - {{ member }} -{% endfor %} +{% for member in beatles -%} +- {{ member }} +{% endfor -%} ``` diff --git a/_filters/strip.md b/_filters/strip.md index a79816a63..f9a7b0d75 100644 --- a/_filters/strip.md +++ b/_filters/strip.md @@ -1,5 +1,6 @@ --- title: strip +category: string description: Liquid filter that removes all whitespace from the left and right sides of a string. --- diff --git a/_filters/strip_html.md b/_filters/strip_html.md index 88425993b..dbbccbe93 100644 --- a/_filters/strip_html.md +++ b/_filters/strip_html.md @@ -1,5 +1,6 @@ --- title: strip_html +category: string description: Liquid filter that removes HTML tags from a string. --- diff --git a/_filters/strip_newlines.md b/_filters/strip_newlines.md index 0a2324bb2..91028b6a4 100644 --- a/_filters/strip_newlines.md +++ b/_filters/strip_newlines.md @@ -1,5 +1,6 @@ --- title: strip_newlines +category: string description: Liquid filter that removes newline characters from a string. --- @@ -22,7 +23,7 @@ there {% capture string_with_newlines %} Hello there -{% endcapture %} +{% endcapture -%} {{ string_with_newlines | strip_newlines }} ``` diff --git a/_filters/times.md b/_filters/times.md index 90c2757a4..e339765b5 100644 --- a/_filters/times.md +++ b/_filters/times.md @@ -1,5 +1,6 @@ --- title: times +category: math description: Liquid filter that multiplies a number by another number. --- diff --git a/_filters/truncate.md b/_filters/truncate.md index 0881fb08f..229264809 100644 --- a/_filters/truncate.md +++ b/_filters/truncate.md @@ -1,5 +1,6 @@ --- title: truncate +category: string description: Liquid filter that truncates a string to a given number of characters. --- @@ -21,32 +22,20 @@ Shortens a string down to the number of characters passed as an argument. If the `truncate` takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence. -The length of the second argument counts against the number of characters specified by the first argument. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use **13** for the first argument of `truncate`, since the ellipsis counts as 3 characters. +You can truncate to the exact number of characters specified by the first argument and avoid showing trailing characters by passing a blank string as the second argument.Input
```liquid {%- raw -%} {{ "Ground control to Major Tom." | truncate: 25, ", and so on" }} +{{ "Ground control to Major Tom." | truncate: 25, "" }} {% endraw %} ```Output
```text {{ "Ground control to Major Tom." | truncate: 25, ", and so on" }} +{{ "Ground control to Major Tom." | truncate: 25, "" }} ``` -### No ellipsis - -You can truncate to the exact number of characters specified by the first argument and avoid showing trailing characters by passing a blank string as the second argument. - -Input
-```liquid -{%- raw -%} -{{ "Ground control to Major Tom." | truncate: 20, "" }} -{% endraw %} -``` - -Output
-```text -{{ "Ground control to Major Tom." | truncate: 20, "" }} -``` +Note that the length of the second argument counts against the number of characters specified by the first argument. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use **13** for the first argument of `truncate`, since the ellipsis counts as 3 characters. diff --git a/_filters/truncatewords.md b/_filters/truncatewords.md index 5cc57a5b6..82ecff051 100644 --- a/_filters/truncatewords.md +++ b/_filters/truncatewords.md @@ -1,5 +1,6 @@ --- title: truncatewords +category: string description: Liquid filter that truncates a string to a given number of words. --- @@ -21,30 +22,18 @@ Shortens a string down to the number of words passed as an argument. If the spec `truncatewords` takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence. -Input
-```liquid -{%- raw -%} -{{ "Ground control to Major Tom." | truncatewords: 3, "--" }} -{% endraw %} -``` - -Output
-```text -{{ "Ground control to Major Tom." | truncatewords: 3, "--" }} -``` - -### No ellipsis - You can avoid showing trailing characters by passing a blank string as the second argument.Input
```liquid {%- raw -%} +{{ "Ground control to Major Tom." | truncatewords: 3, "--" }} {{ "Ground control to Major Tom." | truncatewords: 3, "" }} {% endraw %} ```Output
```text +{{ "Ground control to Major Tom." | truncatewords: 3, "--" }} {{ "Ground control to Major Tom." | truncatewords: 3, "" }} ``` diff --git a/_filters/uniq.md b/_filters/uniq.md index 0f87b5ccb..dcf6a7dd7 100644 --- a/_filters/uniq.md +++ b/_filters/uniq.md @@ -1,5 +1,6 @@ --- title: uniq +category: array description: Liquid filter that removes duplicate items from an array. --- @@ -16,7 +17,7 @@ Removes any duplicate items in an array.Output
```text -{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %} +{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " -%} {{ my_array | uniq | join: ", " }} ``` diff --git a/_filters/upcase.md b/_filters/upcase.md index d131b43c5..8a5cec829 100644 --- a/_filters/upcase.md +++ b/_filters/upcase.md @@ -1,5 +1,6 @@ --- title: upcase +category: string description: Liquid filter that converts a string to uppercase. --- @@ -9,22 +10,12 @@ Makes each character in a string uppercase. It has no effect on strings which ar ```liquid {%- raw -%} {{ "Parker Moore" | upcase }} -{% endraw %} -``` - -Output
-```text -{{ "Parker Moore" | upcase }} -``` - -Input
-```liquid -{%- raw -%} {{ "APPLE" | upcase }} {% endraw %} ```Output
```text +{{ "Parker Moore" | upcase }} {{ "APPLE" | upcase }} ``` diff --git a/_filters/url_decode.md b/_filters/url_decode.md index e5559c932..9ff04bfd1 100644 --- a/_filters/url_decode.md +++ b/_filters/url_decode.md @@ -1,5 +1,6 @@ --- title: url_decode +category: aaa description: Liquid filter that decodes percent-encoded characters in a string. version-badge: 4.0.0 --- diff --git a/_filters/url_encode.md b/_filters/url_encode.md index 74fe92935..644c922b6 100644 --- a/_filters/url_encode.md +++ b/_filters/url_encode.md @@ -1,32 +1,23 @@ --- title: url_encode +category: aaa description: Liquid filter that encodes URL-unsafe characters in a string. --- Converts any URL-unsafe characters in a string into percent-encoded characters. -Input
-```liquid -{%- raw -%} -{{ "john@liquid.com" | url_encode }} -{% endraw %} -``` - -Output
-```text -{{ "john@liquid.com" | url_encode }} -``` - Note that `url_encode` will turn a space into a `+` sign instead of a percent-encoded character.Input
```liquid {%- raw -%} +{{ "john@liquid.com" | url_encode }} {{ "Tetsuro Takara" | url_encode }} {% endraw %} ```Output
```text +{{ "john@liquid.com" | url_encode }} {{ "Tetsuro Takara" | url_encode }} ``` diff --git a/_filters/where.md b/_filters/where.md index 80d800426..a19a45192 100644 --- a/_filters/where.md +++ b/_filters/where.md @@ -1,5 +1,6 @@ --- title: where +category: array description: Liquid filter that selects from arrays. version-badge: 4.0.2 --- @@ -69,7 +70,7 @@ Available products: - Boring sneakers ``` -The `where` filter can also be used to find a single object in an array when combined with the `first` filter. For example, say you want to show off the shirt in your new fall collection. +The `where` filter can also be used to find a single object in an array when combined with the `first` or `last` filter. For example, say you want to show off the shirt in your new fall collection.Input
```liquid diff --git a/_includes/sidebar-link.html b/_includes/sidebar-link.html new file mode 100644 index 000000000..ab45c8e1e --- /dev/null +++ b/_includes/sidebar-link.html @@ -0,0 +1,11 @@ +