diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 76e319405..000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,265 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (6.0.3.5) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.11.1) - colorator (1.1.0) - commonmarker (0.17.13) - ruby-enum (~> 0.5) - concurrent-ruby (1.1.8) - dnsruby (1.61.5) - simpleidn (~> 0.1) - em-websocket (0.5.2) - eventmachine (>= 0.12.9) - http_parser.rb (~> 0.6.0) - ethon (0.12.0) - ffi (>= 1.3.0) - eventmachine (1.2.7) - execjs (2.7.0) - faraday (1.3.0) - faraday-net_http (~> 1.0) - multipart-post (>= 1.2, < 3) - ruby2_keywords - faraday-net_http (1.0.1) - ffi (1.15.0) - forwardable-extended (2.6.0) - gemoji (3.0.1) - github-pages (212) - github-pages-health-check (= 1.17.0) - jekyll (= 3.9.0) - jekyll-avatar (= 0.7.0) - jekyll-coffeescript (= 1.1.1) - jekyll-commonmark-ghpages (= 0.1.6) - jekyll-default-layout (= 0.1.4) - jekyll-feed (= 0.15.1) - jekyll-gist (= 1.5.0) - jekyll-github-metadata (= 2.13.0) - jekyll-mentions (= 1.6.0) - jekyll-optional-front-matter (= 0.3.2) - jekyll-paginate (= 1.1.0) - jekyll-readme-index (= 0.3.0) - jekyll-redirect-from (= 0.16.0) - jekyll-relative-links (= 0.6.1) - jekyll-remote-theme (= 0.4.2) - jekyll-sass-converter (= 1.5.2) - jekyll-seo-tag (= 2.7.1) - jekyll-sitemap (= 1.4.0) - jekyll-swiss (= 1.0.0) - jekyll-theme-architect (= 0.1.1) - jekyll-theme-cayman (= 0.1.1) - jekyll-theme-dinky (= 0.1.1) - jekyll-theme-hacker (= 0.1.2) - jekyll-theme-leap-day (= 0.1.1) - jekyll-theme-merlot (= 0.1.1) - jekyll-theme-midnight (= 0.1.1) - jekyll-theme-minimal (= 0.1.1) - jekyll-theme-modernist (= 0.1.1) - jekyll-theme-primer (= 0.5.4) - jekyll-theme-slate (= 0.1.1) - jekyll-theme-tactile (= 0.1.1) - jekyll-theme-time-machine (= 0.1.1) - jekyll-titles-from-headings (= 0.5.3) - jemoji (= 0.12.0) - kramdown (= 2.3.0) - kramdown-parser-gfm (= 1.1.0) - liquid (= 4.0.3) - mercenary (~> 0.3) - minima (= 2.5.1) - nokogiri (>= 1.10.4, < 2.0) - rouge (= 3.26.0) - terminal-table (~> 1.4) - github-pages-health-check (1.17.0) - addressable (~> 2.3) - dnsruby (~> 1.60) - octokit (~> 4.0) - public_suffix (>= 2.0.2, < 5.0) - typhoeus (~> 1.3) - html-pipeline (2.14.0) - activesupport (>= 2) - nokogiri (>= 1.4) - http_parser.rb (0.6.0) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - jekyll (3.9.0) - addressable (~> 2.4) - colorator (~> 1.0) - em-websocket (~> 0.5) - i18n (~> 0.7) - jekyll-sass-converter (~> 1.0) - jekyll-watch (~> 2.0) - kramdown (>= 1.17, < 3) - liquid (~> 4.0) - mercenary (~> 0.3.3) - pathutil (~> 0.9) - rouge (>= 1.7, < 4) - safe_yaml (~> 1.0) - jekyll-avatar (0.7.0) - jekyll (>= 3.0, < 5.0) - jekyll-coffeescript (1.1.1) - coffee-script (~> 2.2) - coffee-script-source (~> 1.11.1) - jekyll-commonmark (1.3.1) - commonmarker (~> 0.14) - jekyll (>= 3.7, < 5.0) - jekyll-commonmark-ghpages (0.1.6) - commonmarker (~> 0.17.6) - jekyll-commonmark (~> 1.2) - rouge (>= 2.0, < 4.0) - jekyll-default-layout (0.1.4) - jekyll (~> 3.0) - jekyll-feed (0.15.1) - jekyll (>= 3.7, < 5.0) - jekyll-gist (1.5.0) - octokit (~> 4.2) - jekyll-github-metadata (2.13.0) - jekyll (>= 3.4, < 5.0) - octokit (~> 4.0, != 4.4.0) - jekyll-mentions (1.6.0) - html-pipeline (~> 2.3) - jekyll (>= 3.7, < 5.0) - jekyll-optional-front-matter (0.3.2) - jekyll (>= 3.0, < 5.0) - jekyll-paginate (1.1.0) - jekyll-readme-index (0.3.0) - jekyll (>= 3.0, < 5.0) - jekyll-redirect-from (0.16.0) - jekyll (>= 3.3, < 5.0) - jekyll-relative-links (0.6.1) - jekyll (>= 3.3, < 5.0) - jekyll-remote-theme (0.4.2) - addressable (~> 2.0) - jekyll (>= 3.5, < 5.0) - jekyll-sass-converter (>= 1.0, <= 3.0.0, != 2.0.0) - rubyzip (>= 1.3.0, < 3.0) - jekyll-sass-converter (1.5.2) - sass (~> 3.4) - jekyll-seo-tag (2.7.1) - jekyll (>= 3.8, < 5.0) - jekyll-sitemap (1.4.0) - jekyll (>= 3.7, < 5.0) - jekyll-swiss (1.0.0) - jekyll-theme-architect (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-cayman (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-dinky (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-hacker (0.1.2) - jekyll (> 3.5, < 5.0) - jekyll-seo-tag (~> 2.0) - jekyll-theme-leap-day (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-merlot (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-midnight (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-minimal (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-modernist (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-primer (0.5.4) - jekyll (> 3.5, < 5.0) - jekyll-github-metadata (~> 2.9) - jekyll-seo-tag (~> 2.0) - jekyll-theme-slate (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-tactile (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-theme-time-machine (0.1.1) - jekyll (~> 3.5) - jekyll-seo-tag (~> 2.0) - jekyll-titles-from-headings (0.5.3) - jekyll (>= 3.3, < 5.0) - jekyll-watch (2.2.1) - listen (~> 3.0) - jemoji (0.12.0) - gemoji (~> 3.0) - html-pipeline (~> 2.2) - jekyll (>= 3.0, < 5.0) - kramdown (2.3.0) - rexml - kramdown-parser-gfm (1.1.0) - kramdown (~> 2.0) - liquid (4.0.3) - listen (3.4.1) - rb-fsevent (~> 0.10, >= 0.10.3) - rb-inotify (~> 0.9, >= 0.9.10) - mercenary (0.3.6) - mini_portile2 (2.5.0) - minima (2.5.1) - jekyll (>= 3.5, < 5.0) - jekyll-feed (~> 0.9) - jekyll-seo-tag (~> 2.1) - minitest (5.14.4) - multipart-post (2.1.1) - nokogiri (1.11.1) - mini_portile2 (~> 2.5.0) - racc (~> 1.4) - octokit (4.20.0) - faraday (>= 0.9) - sawyer (~> 0.8.0, >= 0.5.3) - pathutil (0.16.2) - forwardable-extended (~> 2.6) - public_suffix (4.0.6) - racc (1.5.2) - rb-fsevent (0.10.4) - rb-inotify (0.10.1) - ffi (~> 1.0) - rexml (3.2.4) - rouge (3.26.0) - ruby-enum (0.9.0) - i18n - ruby2_keywords (0.0.4) - rubyzip (2.3.0) - safe_yaml (1.0.5) - sass (3.7.4) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sawyer (0.8.2) - addressable (>= 2.3.5) - faraday (> 0.8, < 2.0) - simpleidn (0.2.1) - unf (~> 0.1.4) - terminal-table (1.8.0) - unicode-display_width (~> 1.1, >= 1.1.1) - thread_safe (0.3.6) - typhoeus (1.4.0) - ethon (>= 0.9.0) - tzinfo (1.2.9) - thread_safe (~> 0.1) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.7) - unicode-display_width (1.7.0) - zeitwerk (2.4.2) - -PLATFORMS - ruby - -DEPENDENCIES - github-pages (>= 180) - -BUNDLED WITH - 2.1.4 diff --git a/_basics/introduction.md b/_basics/introduction.md index 8e080a4d2..188028b1c 100644 --- a/_basics/introduction.md +++ b/_basics/introduction.md @@ -4,15 +4,15 @@ description: An overview of objects, tags, and filters in the Liquid template la redirect_from: /basics/ --- -Liquid code can be categorized into [**objects**](#objects), [**tags**](#tags), and [**filters**](#filters). +Liquid uses a combination of [**objects**](#intro-objects), [**tags**](#intro-tags), and [**filters**](#intro-filters) inside **template files** to display dynamic content. -## Objects +
Input
```liquid -{% raw %} +{%- raw -%} {{ page.title }} {% endraw %} ``` @@ -22,17 +22,15 @@ Liquid code can be categorized into [**objects**](#objects), [**tags**](#tags), {{ page.title }} ``` -In this case, Liquid is rendering the content of an object called `page.title`, and that object contains the text `Introduction`. +In this case, Liquid is rendering the content of the `title` property of the `page` object, which contains the text `{{ page.title }}`. -## Tags +Input
```liquid -{% raw %} +{%- raw -%} {% if user %} Hello {{ user.name }}! {% endif %} @@ -44,21 +42,22 @@ The markup used in tags does not produce any visible text. This means that you c Hello Adam! ``` -Tags can be categorized into three types: +Tags can be categorized into various types: - [Control flow]({{ "/tags/control-flow/" | prepend: site.baseurl }}) - [Iteration]({{ "/tags/iteration/" | prepend: site.baseurl }}) -- [Variable assignments]({{ "/tags/variable/" | prepend: site.baseurl }}) +- [Template]({{ "/tags/template/" | prepend: site.baseurl }}) +- [Variable assignment]({{ "/tags/variable/" | prepend: site.baseurl }}) You can read more about each type of tag in their respective sections. -## Filters +Input
```liquid -{% raw %} +{%- raw -%} {{ "/my/fancy/url" | append: ".html" }} {% endraw %} ``` @@ -68,11 +67,11 @@ You can read more about each type of tag in their respective sections. {{ "/my/fancy/url" | append: ".html" }} ``` -Multiple filters can be used on one output. They are applied from left to right. +Multiple filters can be used on one output, and are applied from left to right.Input
```liquid -{% raw %} +{%- raw -%} {{ "adam!" | capitalize | prepend: "Hello " }} {% endraw %} ``` @@ -81,3 +80,12 @@ Multiple filters can be used on one output. They 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/operators.md b/_basics/operators.md index 0f945cfe5..a1858c968 100644 --- a/_basics/operators.md +++ b/_basics/operators.md @@ -3,7 +3,7 @@ title: Operators description: Using operators to perform calculations in the Liquid template language. --- -Liquid includes many logical and comparison operators. +Liquid includes many logical and comparison operators. You can use operators to create logic with [control flow]({{ "/tags/control-flow/" | prepend: site.baseurl }}) tags. ## Basic operators @@ -47,17 +47,17 @@ Liquid includes many logical and comparison operators. For example: ```liquid -{% raw %} +{%- raw -%} {% if product.title == "Awesome Shoes" %} These shoes are awesome! {% endif %} {% endraw %} ``` -You can use multiple operators in a tag: +You can do multiple comparisons in a tag using the `and` and `or` operators: ```liquid -{% raw %} +{%- raw -%} {% if product.type == "Shirt" or product.type == "Shoes" %} This is a shirt or a pair of shoes. {% endif %} @@ -69,7 +69,7 @@ You can use multiple operators in a tag: `contains` checks for the presence of a substring inside a string. ```liquid -{% raw %} +{%- raw -%} {% if product.title contains "Pack" %} This product's title contains the word Pack. {% endif %} @@ -79,7 +79,7 @@ You can use multiple operators in a tag: `contains` can also check for the presence of a string in an array of strings. ```liquid -{% raw %} +{%- raw -%} {% if product.tags contains "Hello" %} This product has been tagged with "Hello". {% endif %} @@ -93,7 +93,7 @@ You can use multiple operators in a tag: In tags with more than one `and` or `or` operator, operators are checked in order *from right to left*. You cannot change the order of operations using parentheses — parentheses are invalid characters in Liquid and will prevent your tags from working. ```liquid -{% raw %} +{%- raw -%} {% if true or false and false %} This evaluates to true, since the `and` condition is checked first. {% endif %} @@ -101,7 +101,7 @@ In tags with more than one `and` or `or` operator, operators are checked in orde ``` ```liquid -{% raw %} +{%- raw -%} {% if true and false and false or true %} This evaluates to false, since the tags are checked like this: diff --git a/_basics/truthy-and-falsy.md b/_basics/truthy-and-falsy.md index b1fffb979..c8e48c727 100644 --- a/_basics/truthy-and-falsy.md +++ b/_basics/truthy-and-falsy.md @@ -3,47 +3,43 @@ title: Truthy and falsy description: An overview of boolean logic in the Liquid template language. --- -In programming, anything that returns `true` in a conditional is called **truthy**. Anything that returns `false` in a conditional is called **falsy**. All object types can be described as either truthy or falsy. - -- [Truthy](#truthy) -- [Falsy](#falsy) -- [Summary](#summary) +When a non-boolean [data type]({{ "/basics/types/" | prepend: site.baseurl }}) is used in a boolean context (such as a conditional tag), Liquid decides whether to evaluate it as `true` or `false`. Data types that return `true` by default are called **truthy**. Data types that return false by default are called **falsy**. ## Truthy All values in Liquid are truthy except `nil` and `false`. -In the example below, the string "Tobi" is not a boolean, but it is truthy in a conditional: +In the example below, the text "Tobi" is not a boolean, but it is truthy in a conditional: ```liquid -{% raw %} -{% assign tobi = "Tobi" %} +{%- raw -%} +{% assign name = "Tobi" %} -{% if tobi %} - This condition will always be true. +{% if name %} + This text will always appear if "name" is defined. {% endif %} {% endraw %} ``` -[Strings]({{ "/basics/types/#string" | prepend: site.baseurl }}), even when empty, are truthy. The example below will result in empty HTML tags if `settings.fp_heading` is empty: +[Strings]({{ "/basics/types/#string" | prepend: site.baseurl }}), even when empty, are truthy. The example below will create empty HTML tags if `page.category` exists but is empty:Input
```liquid -{% raw %} -{% if settings.fp_heading %} -Output
```html - + ``` ## Falsy -The falsy values in Liquid are [`nil`]({{ "/basics/types/#nil" | prepend: site.baseurl }}) and [`false`]({{ "/basics/types/#boolean" | prepend: site.baseurl }}). +The only values that are falsy in Liquid are [`nil`]({{ "/basics/types/#nil" | prepend: site.baseurl }}) and [`false`]({{ "/basics/types/#boolean" | prepend: site.baseurl }}). ## Summary diff --git a/_basics/types.md b/_basics/types.md index d7c6c7bf2..9b4e28532 100644 --- a/_basics/types.md +++ b/_basics/types.md @@ -3,22 +3,23 @@ title: Types description: An overview of data types in the Liquid template language. --- -Liquid objects can have one of five types: +Liquid objects can be one of six types: - [String](#string) - [Number](#number) - [Boolean](#boolean) - [Nil](#nil) - [Array](#array) +- [EmptyDrop](#emptydrop) -You can initialize Liquid variables with the [assign]({{ "/tags/variable/#assign" | prepend: site.baseurl }}) or [capture]({{ "/tags/variable/#capture" | prepend: site.baseurl }}) tags. +You can initialize Liquid variables using [`assign`]({{ "/tags/variable/#assign" | prepend: site.baseurl }}) or [`capture`]({{ "/tags/variable/#capture" | prepend: site.baseurl }}) tags. ## String -Declare a string by wrapping a variable's value in single or double quotes: +Strings are declared by wrapping a variable's value in single or double quotes: ```liquid -{% raw %} +{%- raw -%} {% assign my_string = "Hello World!" %} {% endraw %} ``` @@ -28,9 +29,9 @@ Declare a string by wrapping a variable's value in single or double quotes: Numbers include floats and integers: ```liquid -{% raw %} +{%- raw -%} {% assign my_int = 25 %} -{% assign my_float = 39.756 %} +{% assign my_float = -39.756 %} {% endraw %} ``` @@ -39,7 +40,7 @@ Numbers include floats and integers: Booleans are either `true` or `false`. No quotations are necessary when declaring a boolean: ```liquid -{% raw %} +{%- raw -%} {% assign foo = true %} {% assign bar = false %} {% endraw %} @@ -54,7 +55,7 @@ Nil is [treated as false]({{ "/basics/truthy-and-falsy/#falsy" | prepend: site.b In the following example, if the user does not exist (that is, `user` returns `nil`), Liquid will not print the greeting: ```liquid -{% raw %} +{%- raw -%} {% if user %} Hello {{ user.name }}! {% endif %} @@ -65,7 +66,7 @@ Tags or outputs that return `nil` will not print anything to the page.Input
```liquid -{% raw %} +{%- raw -%} The current user is {{ user.name }} {% endraw %} ``` @@ -85,7 +86,7 @@ To access all the items in an array, you can loop through each item in the arrayInput
```liquid -{% raw %} +{%- raw -%} {% for user in site.users %} {{ user }} @@ -100,15 +101,15 @@ Tobi Laura Tetsuro Adam ### Accessing specific items in arrays -You can use square bracket `[` `]` notation to access a specific item in an array. Array indexing starts at zero. +You can use square bracket `[` `]` notation to access a specific item in an array. Array indexing starts at zero. A negative index will count from the end of the array.Input
```liquid -{% raw %} +{%- raw -%} {{ site.users[0] }} {{ site.users[1] }} -{{ site.users[3] }} +{{ site.users[-1] }} {% endraw %} ``` @@ -123,4 +124,32 @@ Adam You cannot initialize arrays using only Liquid. -You can, however, use the [split]({{ "/filters/split/" | prepend: site.baseurl }}) filter to break a string into an array of substrings. +You can, however, use the [`split`]({{ "/filters/split/" | prepend: site.baseurl }}) filter to break a string into an array of substrings. + +## EmptyDrop + +An EmptyDrop object is returned if you try to access a deleted object. In the example below, `page_1`, `page_2` and `page_3` are all EmptyDrop objects: + +```liquid +{%- raw -%} +{% assign variable = "hello" %} +{% assign page_1 = pages[variable] %} +{% assign page_2 = pages["does-not-exist"] %} +{% assign page_3 = pages.this-handle-does-not-exist %} +{% endraw %} +``` + +### Checking for emptiness + +You can check to see if an object exists or not before you access any of its attributes. + +```liquid +{%- raw -%} +{% unless pages == empty %} +Input
```liquid -{% raw %} +{%- raw -%} {% assign my_variable = "tomato" %} {{ my_variable }} {% endraw %} @@ -27,7 +27,7 @@ By including hyphens in your `assign` tag, you can strip the generated whitespacInput
```liquid -{% raw %} +{%- raw -%} {%- assign my_variable = "tomato" -%} {{ my_variable }} {% endraw %} @@ -38,14 +38,16 @@ By including hyphens in your `assign` tag, you can strip the generated whitespac tomato ``` +## 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
```liquid -{% raw %} +{%- raw -%} {% assign username = "John G. Chalmers-Smith" %} {% if username and username.size > 10 %} - Wow, {{ username }}, you have a long name! + Wow, {{ username }} , you have a long name! {% else %} Hello there! {% endif %} @@ -56,7 +58,7 @@ If you don't want any of your tags to print whitespace, as a general rule you ca ```text {% assign username = "John G. Chalmers-Smith" %} {% if username and username.size > 10 %} - Wow, {{ username }}, you have a long name! + Wow, {{ username }} , you have a long name! {% else %} Hello there! {% endif %} @@ -64,17 +66,43 @@ If you don't want any of your tags to print whitespace, as a general rule you caInput
```liquid -{% raw %} -{%- assign username = "John G. Chalmers-Smith" -%} +{%- raw -%} +{% assign username = "John G. Chalmers-Smith" -%} {%- if username and username.size > 10 -%} - Wow, {{ username }}, you have a long name! + Wow, {{ username -}} , you have a long name! {%- else -%} Hello there! -{%- endif -%} +{%- endif %} {% endraw %} ```Output with whitespace control
```text -Wow, John G. Chalmers-Smith, you have a long name! +{% assign username = "John G. Chalmers-Smith" -%} +{%- if username and username.size > 10 -%} + Wow, {{ username -}} , you have a long name! +{%- else -%} + Hello there! +{%- endif %} +``` + +## Avoiding whitespace without hyphens {%- include version-badge.html version="5.0.0" %} + +If you use the [`liquid`]({{ '/tags/template#liquid500' | 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 ee28e19bd..72e38a5fd 100644 --- a/_filters/abs.md +++ b/_filters/abs.md @@ -1,45 +1,23 @@ --- 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 %} +{%- raw -%} {{ -17 | abs }} -{% endraw %} -``` - -Output
-```text -{{ -17 | abs }} -``` - -Input
-```liquid -{% raw %} {{ 4 | abs }} -{% endraw %} -``` - -Output
-```text -{{ 4 | abs }} -``` - -`abs` will also work on a string that only contains a number: - -Input
-```liquid -{% raw %} {{ "-19.86" | abs }} {% endraw %} ```Output
```text +{{ -17 | abs }} +{{ 4 | abs }} {{ "-19.86" | abs }} ``` diff --git a/_filters/append.md b/_filters/append.md index 9c0bc1626..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. --- -Concatenates two strings and returns the concatenated value. +Adds the specified string to the end of another string. `append` can also accept a variable as its argument.Input
```liquid -{% raw %} +{%- 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 be used with variables: - -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 3bb2b141f..3b0a9faea 100644 --- a/_filters/at_least.md +++ b/_filters/at_least.md @@ -1,30 +1,22 @@ --- title: at_least +category: math description: Liquid filter that limits a number to a minimum value. +version-badge: 4.0.1 --- Limits a number to a minimum value.Input
```liquid -{% raw %} +{%- raw -%} {{ 4 | at_least: 5 }} -{% endraw %} -``` - -Output
-```text -5 -``` - -Input
-```liquid -{% raw %} {{ 4 | at_least: 3 }} {% endraw %} ```Output
```text -4 +{{ 4 | at_least: 5 }} +{{ 4 | at_least: 3 }} ``` diff --git a/_filters/at_most.md b/_filters/at_most.md index 9599ee218..6a083ab03 100644 --- a/_filters/at_most.md +++ b/_filters/at_most.md @@ -1,30 +1,22 @@ --- title: at_most +category: math description: Liquid filter that limits a number to a maximum value. +version-badge: 4.0.1 --- Limits a number to a maximum value.Input
```liquid -{% raw %} +{%- raw -%} {{ 4 | at_most: 5 }} -{% endraw %} -``` - -Output
-```text -4 -``` - -Input
-```liquid -{% raw %} {{ 4 | at_most: 3 }} {% endraw %} ```Output
```text -3 +{{ 4 | at_most: 5 }} +{{ 4 | at_most: 3 }} ``` diff --git a/_filters/capitalize.md b/_filters/capitalize.md index 72a461e34..d82fd6544 100644 --- a/_filters/capitalize.md +++ b/_filters/capitalize.md @@ -1,32 +1,21 @@ --- title: capitalize +category: string description: Liquid filter that capitalizes the first character of a string. --- -Makes the first character of a string capitalized. +Makes the first character of a string capitalized and downcases the rest.Input
```liquid -{% raw %} +{%- raw -%} {{ "title" | capitalize }} +{{ "my GREAT title" | capitalize }} {% endraw %} ```Output
```text {{ "title" | capitalize }} -``` - -`capitalize` only capitalizes the first character of a string, so later words are not affected: - -Input
-```liquid -{% raw %} -{{ "my great title" | capitalize }} -{% endraw %} -``` - -Output
-```text -{{ "my great title" | capitalize }} +{{ "my GREAT title" | capitalize }} ``` diff --git a/_filters/ceil.md b/_filters/ceil.md index debc68881..1a81d6d3e 100644 --- a/_filters/ceil.md +++ b/_filters/ceil.md @@ -1,56 +1,25 @@ --- title: ceil +category: math description: Liquid filter that returns the ceiling of a number by rounding up to the nearest integer. --- -Rounds the 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 -{% raw %} +{%- raw -%} {{ 1.2 | ceil }} -{% endraw %} -``` - -Output
-```text -{{ 1.2 | ceil }} -``` - -Input
-```liquid -{% raw %} -{{ 2.0 | ceil }} -{% endraw %} -``` - -Output
-```text {{ 2.0 | ceil }} -``` - -Input
-```liquid -{% raw %} -{{ 183.357 | ceil }} -{% endraw %} -``` - -Output
-```text {{ 183.357 | ceil }} -``` - -Here the input value is a string: - -Input
-```liquid -{% raw %} {{ "3.5" | ceil }} {% endraw %} ```Output
```text +{{ 1.2 | ceil }} +{{ 2.0 | ceil }} +{{ 183.357 | ceil }} {{ "3.5" | ceil }} ``` diff --git a/_filters/compact.md b/_filters/compact.md index 2847104e6..bad7c5b72 100644 --- a/_filters/compact.md +++ b/_filters/compact.md @@ -1,6 +1,8 @@ --- title: compact +category: array description: Liquid filter that removes nil values from an array. +version-badge: 4.0.0 --- Removes any `nil` values from an array. @@ -9,7 +11,7 @@ For this example, assume `site.pages` is an array of content pages for a websiteInput
```liquid -{% raw %} +{%- raw -%} {% assign site_categories = site.pages | map: "category" %} {% for category in site_categories %} @@ -33,7 +35,7 @@ By using `compact` when we create our `site_categories` array, we can remove allInput
```liquid -{% raw %} +{%- raw -%} {% assign site_categories = site.pages | map: "category" | compact %} {% for category in site_categories %} diff --git a/_filters/concat.md b/_filters/concat.md index a41b60480..6c2fef36d 100644 --- a/_filters/concat.md +++ b/_filters/concat.md @@ -1,13 +1,15 @@ --- title: concat +category: array description: Liquid filter that concatenates arrays. +version-badge: 4.0.0 --- Concatenates (joins together) multiple arrays. The resulting array contains all the items from the input arrays.Input
```liquid -{% raw %} +{%- raw -%} {% assign fruits = "apples, oranges, peaches" | split: ", " %} {% assign vegetables = "carrots, turnips, potatoes" | split: ", " %} @@ -29,11 +31,11 @@ Concatenates (joins together) multiple arrays. The resulting array contains all - potatoes ``` -You can string together `concat` filters to join more than two arrays: +You can string together multiple `concat` filters to join more than two arrays.Input
```liquid -{% raw %} +{%- raw -%} {% assign furniture = "chairs, tables, shelves" | split: ", " %} {% assign everything = fruits | concat: vegetables | concat: furniture %} diff --git a/_filters/date.md b/_filters/date.md index 69be3ec37..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 -``` +`date` works on strings if they contain well-formatted dates. +To get the current time, pass the special word `"now"` (or `"today"`) to `date`.Input
```liquid -{% raw %} +{%- raw -%} +{{ article.published_at | date: "%a, %b %d, %y" }} {{ 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 %} 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 9437cd507..c8a4f08e1 100644 --- a/_filters/default.md +++ b/_filters/default.md @@ -1,50 +1,45 @@ --- title: default +category: aaa description: Liquid filter that specifies a fallback in case a value doesn't exist. --- -Allows you to specify a fallback in case a value doesn't exist. `default` will show its value if the left side is `nil`, `false`, or empty. +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 %} +{%- 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 -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 %} +{% assign product_price = 4.99 -%} {{ product_price | default: 2.99 }} +{% assign product_price = "" -%} {{ product_price | default: 2.99 }} ``` -Output
-```text -4.99 -``` +### Allowing `false` {%- include version-badge.html version="5.0.0" %} -In this example, `product_price` is empty, so the default value is used. +To allow variables to return `false` instead of the default value, you can use the `allow_false` parameter.Input
```liquid -{% raw %} -{% assign product_price = "" %} -{{ product_price | default: 2.99 }} +{%- raw -%} +{% assign display_price = false %} +{{ display_price | default: true, allow_false: true }} {% endraw %} ```Output
```text -2.99 +false ``` diff --git a/_filters/divided_by.md b/_filters/divided_by.md index f87d9b19b..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. --- @@ -9,25 +10,15 @@ The result is rounded down to the nearest integer (that is, the [floor]({{ "/filInput
```liquid -{% raw %} +{%- raw -%} {{ 16 | divided_by: 4 }} -{% endraw %} -``` - -Output
-```text -{{ 16 | divided_by: 4 }} -``` - -Input
-```liquid -{% raw %} {{ 5 | divided_by: 3 }} {% endraw %} ```Output
```text +{{ 16 | divided_by: 4 }} {{ 5 | divided_by: 3 }} ``` @@ -35,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 %} +{%- 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 %} +{%- raw -%} +{% assign my_integer = 7 %} {{ 20 | divided_by: my_integer }} {% assign my_float = my_integer | times: 1.0 %} {{ 20 | divided_by: my_float }} {% endraw %} @@ -96,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 e66239efb..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. --- @@ -7,24 +8,14 @@ Makes each character in a string lowercase. It has no effect on strings which arInput
```liquid -{% raw %} +{%- 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 479325b5f..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. --- @@ -7,24 +8,14 @@ Escapes a string by replacing characters with escape sequences (so that the striInput
```liquid -{% raw %} +{%- 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 6ee787ec0..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 %} +{%- 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 a5345975b..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. --- @@ -7,36 +8,26 @@ Returns the first item of an array.Input
```liquid -{% raw %} +{%- 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 }} ``` You can use `first` with dot notation when you need to use the filter inside a tag: ```liquid -{% raw %} +{%- raw -%} {% if my_array.first == "zebra" %} Here comes a zebra! {% endif %} diff --git a/_filters/floor.md b/_filters/floor.md index 1b1269784..ece193228 100644 --- a/_filters/floor.md +++ b/_filters/floor.md @@ -1,56 +1,25 @@ --- title: floor +category: math description: Liquid filter that returns the floor of a number by rounding down to the nearest integer. --- -Rounds the 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 -{% raw %} +{%- raw -%} {{ 1.2 | floor }} -{% endraw %} -``` - -Output
-```text -{{ 1.2 | floor }} -``` - -Input
-```liquid -{% raw %} -{{ 2.0 | floor }} -{% endraw %} -``` - -Output
-```text {{ 2.0 | floor }} -``` - -Input
-```liquid -{% raw %} -{{ 183.357 | floor }} -{% endraw %} -``` - -Output
-```text {{ 183.357 | floor }} -``` - -Here the input value is a string: - -Input
-```liquid -{% raw %} {{ "3.5" | floor }} {% endraw %} ```Output
```text +{{ 1.2 | floor }} +{{ 2.0 | floor }} +{{ 183.357 | floor }} {{ "3.5" | floor }} ``` diff --git a/_filters/join.md b/_filters/join.md index 2cd589ce3..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. --- @@ -7,7 +8,7 @@ Combines the items in an array into a single string using the argument as a sepaInput
```liquid -{% raw %} +{%- raw -%} {% assign beatles = "John, Paul, George, Ringo" | split: ", " %} {{ beatles | join: " and " }} @@ -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 5337abbed..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. --- @@ -7,36 +8,26 @@ Returns the last item of an array.Input
```liquid -{% raw %} +{%- 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 }} ``` You can use `last` with dot notation when you need to use the filter inside a tag: ```liquid -{% raw %} +{%- raw -%} {% if my_array.last == "tiger" %} There goes a tiger! {% endif %} diff --git a/_filters/lstrip.md b/_filters/lstrip.md index c9b929402..01d9a062c 100644 --- a/_filters/lstrip.md +++ b/_filters/lstrip.md @@ -1,18 +1,19 @@ --- title: lstrip +category: string description: Liquid filter that removes all whitespace from the left side of a string. --- -Removes all whitespace (tabs, spaces, and newlines) from the left side of a string. It does not affect spaces between words. +Removes all whitespace (tabs, spaces, and newlines) from the **left** side of a string. It does not affect spaces between words.Input
```liquid -{% raw %} -{{ " So much room for activities! " | lstrip }} +{%- raw -%} +{{ " So much room for activities " | lstrip }}! {% endraw %} ```Output
```text -{{ " So much room for activities! " | lstrip }} +{{ " So much room for activities " | lstrip }}! ``` diff --git a/_filters/map.md b/_filters/map.md index ddeff2014..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. --- @@ -9,7 +10,7 @@ In this example, assume the object `site.pages` contains all the metadata for aInput
```liquid -{% raw %} +{%- raw -%} {% assign all_categories = site.pages | map: "category" %} {% for item in all_categories %} diff --git a/_filters/minus.md b/_filters/minus.md index d1f65b5a2..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. --- @@ -7,36 +8,16 @@ Subtracts a number from another number.Input
```liquid -{% raw %} +{%- raw -%} {{ 4 | minus: 2 }} -{% endraw %} -``` - -Output
-```text -{{ 4 | minus: 2 }} -``` - -Input
-```liquid -{% raw %} -{{ 16 | minus: 4 }} -{% endraw %} -``` - -Output
-```text {{ 16 | minus: 4 }} -``` - -Input
-```liquid -{% raw %} {{ 183.357 | minus: 12 }} {% endraw %} ```Output
```text +{{ 4 | minus: 2 }} +{{ 16 | minus: 4 }} {{ 183.357 | minus: 12 }} ``` diff --git a/_filters/modulo.md b/_filters/modulo.md index 17e79bc35..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. --- @@ -7,36 +8,16 @@ Returns the remainder of a division operation.Input
```liquid -{% raw %} +{%- raw -%} {{ 3 | modulo: 2 }} -{% endraw %} -``` - -Output
-```text -{{ 3 | modulo: 2 }} -``` - -Input
-```liquid -{% raw %} -{{ 24 | modulo: 7 }} -{% endraw %} -``` - -Output
-```text {{ 24 | modulo: 7 }} -``` - -Input
-```liquid -{% raw %} {{ 183.357 | modulo: 12 }} {% endraw %} ```Output
```text +{{ 3 | modulo: 2 }} +{{ 24 | modulo: 7 }} {{ 183.357 | modulo: 12 }} ``` diff --git a/_filters/newline_to_br.md b/_filters/newline_to_br.md index 89b280d09..abbf974eb 100644 --- a/_filters/newline_to_br.md +++ b/_filters/newline_to_br.md @@ -1,13 +1,14 @@ --- title: newline_to_br +category: string description: Liquid filter that converts newlines in a string to HTMLInput
```liquid -{% raw %} +{%- raw -%} {% capture string_with_newlines %} Hello there @@ -22,7 +23,7 @@ there {% capture string_with_newlines %} Hello there -{% endcapture %} +{% endcapture -%} {{ string_with_newlines | newline_to_br }} ``` diff --git a/_filters/plus.md b/_filters/plus.md index 110022054..f9dbfef57 100644 --- a/_filters/plus.md +++ b/_filters/plus.md @@ -1,5 +1,6 @@ --- title: plus +category: math description: Liquid filter that adds one number to another number. --- @@ -7,36 +8,16 @@ Adds a number to another number.Input
```liquid -{% raw %} +{%- raw -%} {{ 4 | plus: 2 }} -{% endraw %} -``` - -Output
-```text -{{ 4 | plus: 2 }} -``` - -Input
-```liquid -{% raw %} -{{ 16 | plus: 4 }} -{% endraw %} -``` - -Output
-```text {{ 16 | plus: 4 }} -``` - -Input
-```liquid -{% raw %} {{ 183.357 | plus: 12 }} {% endraw %} ```Output
```text +{{ 4 | plus: 2 }} +{{ 16 | plus: 4 }} {{ 183.357 | plus: 12 }} ``` diff --git a/_filters/prepend.md b/_filters/prepend.md index 5df4708ba..e268fd141 100644 --- a/_filters/prepend.md +++ b/_filters/prepend.md @@ -1,34 +1,21 @@ --- title: prepend +category: string description: Liquid filter that prepends a string to the beginning of another string. --- -Adds the specified string to the beginning of another string. +Adds the specified string to the beginning of another string. `prepend` can also accept a variable as its argument.Input
```liquid -{% raw %} +{%- 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 be used with variables: - -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 0a294abac..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. --- @@ -7,7 +8,7 @@ Removes every occurrence of the specified substring from a string.Input
```liquid -{% raw %} +{%- raw -%} {{ "I strained to see the train through the rain" | remove: "rain" }} {% endraw %} ``` diff --git a/_filters/remove_first.md b/_filters/remove_first.md index ead16b95e..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. --- @@ -7,7 +8,7 @@ Removes only the first occurrence of the specified substring from a string.Input
```liquid -{% raw %} +{%- raw -%} {{ "I strained to see the train through the rain" | remove_first: "rain" }} {% endraw %} ``` diff --git a/_filters/replace.md b/_filters/replace.md index aba612f97..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. --- @@ -7,7 +8,7 @@ Replaces every occurrence of the first argument in a string with the second arguInput
```liquid -{% raw %} +{%- raw -%} {{ "Take my protein pills and put my helmet on" | replace: "my", "your" }} {% endraw %} ``` diff --git a/_filters/replace_first.md b/_filters/replace_first.md index c25ee3ac8..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. --- @@ -7,7 +8,7 @@ Replaces only the first occurrence of the first argument in a string with the seInput
```liquid -{% raw %} +{%- raw -%} {{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }} {% endraw %} ``` diff --git a/_filters/reverse.md b/_filters/reverse.md index 3832f67c2..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. --- @@ -7,7 +8,7 @@ Reverses the order of the items in an array. `reverse` cannot reverse a string.Input
```liquid -{% raw %} +{%- raw -%} {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {{ my_array | reverse | join: ", " }} @@ -16,16 +17,16 @@ 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: ", " }} ``` -Although `reverse` cannot be used directly on a string, you can split a string into an array, reverse the array, and rejoin it by chaining together filters: +Although `reverse` cannot be used directly on a string, you can split a string into an array, reverse the array, and rejoin it by chaining together filters.Input
```liquid -{% raw %} +{%- raw -%} {{ "Ground control to Major Tom." | split: "" | reverse | join: "" }} {% endraw %} ``` diff --git a/_filters/round.md b/_filters/round.md index d95c4fa77..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. --- @@ -7,36 +8,16 @@ Rounds a number to the nearest integer or, if a number is passed as an argument,Input
```liquid -{% raw %} +{%- raw -%} {{ 1.2 | round }} -{% endraw %} -``` - -Output
-```text -{{ 1.2 | round }} -``` - -Input
-```liquid -{% raw %} -{{ 2.7 | round }} -{% endraw %} -``` - -Output
-```text {{ 2.7 | round }} -``` - -Input
-```liquid -{% raw %} {{ 183.357 | round: 2 }} {% endraw %} ```Output
```text +{{ 1.2 | round }} +{{ 2.7 | round }} {{ 183.357 | round: 2 }} ``` diff --git a/_filters/rstrip.md b/_filters/rstrip.md index 25e64f266..b037d4ac9 100644 --- a/_filters/rstrip.md +++ b/_filters/rstrip.md @@ -1,18 +1,19 @@ --- title: rstrip +category: string description: Liquid filter that removes all whitespace from the right side of a string. --- -Removes all whitespace (tabs, spaces, and newlines) from the right side of a string. It does not affect spaces between words. +Removes all whitespace (tabs, spaces, and newlines) from the **right** side of a string. It does not affect spaces between words.Input
```liquid -{% raw %} -{{ " So much room for activities! " | rstrip }} +{%- raw -%} +{{ " So much room for activities " | rstrip }}! {% endraw %} ```Output
```text -{{ " So much room for activities! " | rstrip }} +{{ " So much room for activities " | rstrip }}! ``` diff --git a/_filters/size.md b/_filters/size.md index 96d8a096a..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. --- @@ -7,36 +8,26 @@ Returns the number of characters in a string or the number of items in an array.Input
```liquid -{% raw %} +{%- 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 }} ``` You can use `size` with dot notation when you need to use the filter inside a tag: ```liquid -{% raw %} +{%- raw -%} {% if site.pages.size > 10 %} This is a big website! {% endif %} diff --git a/_filters/slice.md b/_filters/slice.md index eeb1bb8a0..4ce55d552 100644 --- a/_filters/slice.md +++ b/_filters/slice.md @@ -1,58 +1,43 @@ --- title: slice -description: Liquid filter that returns a substring from a given position in a string. +category: string +description: Liquid filter that returns a substring or item from a given position in a string or array. --- -Returns a substring of 1 character beginning at the index specified by the first argument. An optional second argument specifies the length of the substring to be returned. +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 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 %} +{%- 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 }} ``` -If the first argument is a negative number, the indices are counted from the end of the string: +When the input value is an array, the matching items are concatenated and returned:Input
```liquid -{% raw %} -{{ "Liquid" | slice: -3, 2 }} +{%- raw -%} +{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} +{{ beatles | slice: 1, 2 }} {% endraw %} ```Output
```text -{{ "Liquid" | slice: -3, 2 }} +{% assign beatles = "John, Paul, George, Ringo" | split: ", " -%} +{{ beatles | slice: 1, 2 }} ``` diff --git a/_filters/sort.md b/_filters/sort.md index f890d5cef..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. --- @@ -7,7 +8,7 @@ Sorts items in an array in case-sensitive order.Input
```liquid -{% raw %} +{%- raw -%} {% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} {{ my_array | sort | join: ", " }} @@ -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: ", " }} ``` @@ -24,7 +25,7 @@ Sorts items in an array in case-sensitive order. An optional argument specifies which property of the array's items to use for sorting. ```liquid -{% raw %} +{%- raw -%} {% assign products_by_price = collection.products | sort: "price" %} {% for product in products_by_price %}Input
```liquid -{% raw %} +{%- raw -%} {% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} {{ my_array | sort_natural | join: ", " }} @@ -16,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: ", " }} ``` @@ -24,7 +26,7 @@ Sorts items in an array in case-insensitive order. An optional argument specifies which property of the array's items to use for sorting. ```liquid -{% raw %} +{%- raw -%} {% assign products_by_company = collection.products | sort_natural: "company" %} {% for product in products_by_company %}Input
```liquid -{% raw %} +{%- raw -%} {% 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 3efdad252..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. --- @@ -7,12 +8,12 @@ Removes all whitespace (tabs, spaces, and newlines) from both the left and rightInput
```liquid -{% raw %} -{{ " So much room for activities! " | strip }} +{%- raw -%} +{{ " So much room for activities " | strip }}! {% endraw %} ```Output
```text -{{ " So much room for activities! " | strip }} +{{ " So much room for activities " | strip }}! ``` diff --git a/_filters/strip_html.md b/_filters/strip_html.md index 9ca00f086..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. --- @@ -7,7 +8,7 @@ Removes any HTML tags from a string.Input
```liquid -{% raw %} +{%- raw -%} {{ "Have you read Ulysses?" | strip_html }} {% endraw %} ``` diff --git a/_filters/strip_newlines.md b/_filters/strip_newlines.md index c05deaa36..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. --- @@ -7,7 +8,7 @@ Removes any newline characters (line breaks) from a string.Input
```liquid -{% raw %} +{%- raw -%} {% capture string_with_newlines %} Hello there @@ -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 634c7e49d..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. --- @@ -7,36 +8,16 @@ Multiplies a number by another number.Input
```liquid -{% raw %} +{%- raw -%} {{ 3 | times: 2 }} -{% endraw %} -``` - -Output
-```text -{{ 3 | times: 2 }} -``` - -Input
-```liquid -{% raw %} -{{ 24 | times: 7 }} -{% endraw %} -``` - -Output
-```text {{ 24 | times: 7 }} -``` - -Input
-```liquid -{% raw %} {{ 183.357 | times: 12 }} {% endraw %} ```Output
```text +{{ 3 | times: 2 }} +{{ 24 | times: 7 }} {{ 183.357 | times: 12 }} ``` diff --git a/_filters/truncate.md b/_filters/truncate.md index c0b0a4e39..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. --- @@ -7,7 +8,7 @@ Shortens a string down to the number of characters passed as an argument. If theInput
```liquid -{% raw %} +{%- raw -%} {{ "Ground control to Major Tom." | truncate: 20 }} {% endraw %} ``` @@ -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 %} +{%- 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 6d5c5ab1a..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. --- @@ -7,7 +8,7 @@ Shortens a string down to the number of words passed as an argument. If the specInput
```liquid -{% raw %} +{%- raw -%} {{ "Ground control to Major Tom." | truncatewords: 3 }} {% endraw %} ``` @@ -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: +You can avoid showing trailing characters by passing a blank string as the second argument.Input
```liquid -{% raw %} +{%- 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 e02b4e9d2..dcf6a7dd7 100644 --- a/_filters/uniq.md +++ b/_filters/uniq.md @@ -1,13 +1,14 @@ --- title: uniq +category: array description: Liquid filter that removes duplicate items from an array. --- -Removes any duplicate elements in an array. +Removes any duplicate items in an array.Input
```liquid -{% raw %} +{%- raw -%} {% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %} {{ my_array | uniq | join: ", " }} @@ -16,7 +17,7 @@ Removes any duplicate elements 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 627853723..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. --- @@ -7,24 +8,14 @@ Makes each character in a string uppercase. It has no effect on strings which arInput
```liquid -{% raw %} +{%- 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 bf240c194..9ff04bfd1 100644 --- a/_filters/url_decode.md +++ b/_filters/url_decode.md @@ -1,13 +1,15 @@ --- title: url_decode +category: aaa description: Liquid filter that decodes percent-encoded characters in a string. +version-badge: 4.0.0 --- -Decodes a string that has been encoded as a URL or by [url_encode]({{ "/filters/url_encode/" | prepend: site.baseurl }}). +Decodes a string that has been encoded as a URL or by [`url_encode`]({{ "/filters/url_encode/" | prepend: site.baseurl }}).Input
```liquid -{% raw %} +{%- raw -%} {{ "%27Stop%21%27+said+Fred" | url_decode }} {% endraw %} ``` diff --git a/_filters/url_encode.md b/_filters/url_encode.md index 5a17c8130..644c922b6 100644 --- a/_filters/url_encode.md +++ b/_filters/url_encode.md @@ -1,30 +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 %} +{%- 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 70f797f03..a19a45192 100644 --- a/_filters/where.md +++ b/_filters/where.md @@ -1,6 +1,8 @@ --- title: where +category: array description: Liquid filter that selects from arrays. +version-badge: 4.0.2 --- Creates an array including only the objects with a given property value, or any [truthy]({{ "/basics/truthy-and-falsy/#truthy" | prepend: site.baseurl }}) value by default. @@ -9,7 +11,7 @@ In this example, assume you have a list of products and you want to show your kiInput
```liquid -{% raw %} +{%- raw -%} All products: {% for product in products %} - {{ product.title }} @@ -41,7 +43,7 @@ Say instead you have a list of products and you only want to show those that areInput
```liquid -{% raw %} +{%- raw -%} All products: {% for product in products %} - {{ product.title }} @@ -68,11 +70,11 @@ 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 -{% raw %} +{%- raw -%} {% assign new_shirt = products | where: "type", "shirt" | first %} Featured product: {{ new_shirt.title }} diff --git a/_includes/sidebar-link.html b/_includes/sidebar-link.html new file mode 100644 index 000000000..512f8d159 --- /dev/null +++ b/_includes/sidebar-link.html @@ -0,0 +1,11 @@ +