Drop blank lines from input examples

This commit is contained in:
EricFromCanada
2021-04-22 17:08:46 -04:00
parent 77c2dfa989
commit b98d3d6097
57 changed files with 152 additions and 152 deletions

View File

@@ -12,7 +12,7 @@ Liquid uses a combination of [**objects**](#objects), [**tags**](#tags), and [**
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ page.title }}
{% endraw %}
```
@@ -30,7 +30,7 @@ In this case, Liquid is rendering the content of the `title` property of the `pa
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% if user %}
Hello {{ user.name }}!
{% endif %}
@@ -57,7 +57,7 @@ You can read more about each type of tag in their respective sections.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "/my/fancy/url" | append: ".html" }}
{% endraw %}
```
@@ -71,7 +71,7 @@ Multiple filters can be used on one output, and are applied from left to right.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "adam!" | capitalize | prepend: "Hello " }}
{% endraw %}
```

View File

@@ -47,7 +47,7 @@ Liquid includes many logical and comparison operators. You can use operators to
For example:
```liquid
{% raw %}
{%- raw -%}
{% if product.title == "Awesome Shoes" %}
These shoes are awesome!
{% endif %}
@@ -57,7 +57,7 @@ For example:
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 do multiple comparisons in a tag using the `and` and `or` operators:
`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 do multiple comparisons in a tag using the `and` and `or` operators:
`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 do multiple comparisons in a tag using the `and` and `or` operators:
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:

View File

@@ -12,7 +12,7 @@ All values in Liquid are truthy except `nil` and `false`.
In the example below, the text "Tobi" is not a boolean, but it is truthy in a conditional:
```liquid
{% raw %}
{%- raw -%}
{% assign name = "Tobi" %}
{% if name %}
@@ -25,7 +25,7 @@ In the example below, the text "Tobi" is not a boolean, but it is truthy in a co
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% if page.category %}
<h1>{{ page.category }}</h1>
{% endif %}

View File

@@ -19,7 +19,7 @@ You can initialize Liquid variables using [`assign`]({{ "/tags/variable/#assign"
Strings are sequences of characters wrapped in single or double quotes:
```liquid
{% raw %}
{%- raw -%}
{% assign my_string = "Hello World!" %}
{% endraw %}
```
@@ -31,7 +31,7 @@ Liquid does not convert escape sequences into special characters.
Numbers include floats and integers:
```liquid
{% raw %}
{%- raw -%}
{% assign my_int = 25 %}
{% assign my_float = -39.756 %}
{% endraw %}
@@ -42,7 +42,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 %}
@@ -57,7 +57,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 %}
@@ -68,7 +68,7 @@ Tags or outputs that return `nil` will not print anything to the page.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
The current user is {{ user.name }}
{% endraw %}
```
@@ -88,7 +88,7 @@ To access all the items in an array, you can loop through each item in the array
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
{% for user in site.users %}
{{ user }}
@@ -107,7 +107,7 @@ You can use square bracket `[` `]` notation to access a specific item in an arra
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
{{ site.users[0] }}
{{ site.users[1] }}
@@ -133,7 +133,7 @@ You can, however, use the [`split`]({{ "/filters/split/" | prepend: site.baseurl
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 %}
{%- raw -%}
{% assign variable = "hello" %}
{% assign page_1 = pages[variable] %}
{% assign page_2 = pages["does-not-exist"] %}
@@ -146,7 +146,7 @@ An EmptyDrop object is returned if you try to access a deleted object. In the ex
You can check to see if an object exists or not before you access any of its attributes.
```liquid
{% raw %}
{%- raw -%}
{% unless pages == empty %}
<h1>{{ pages.frontpage.title }}</h1>
<div>{{ pages.frontpage.content }}</div>

View File

@@ -9,7 +9,7 @@ Normally, even if it doesn't print text, any line of Liquid in your template wil
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_variable = "tomato" %}
{{ my_variable }}
{% endraw %}
@@ -27,7 +27,7 @@ By including a hyphen in your `assign` closing delimiter, you can strip the whit
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_variable = "tomato" -%}
{{ my_variable }}
{% endraw %}
@@ -43,7 +43,7 @@ If you don't want any of your tags to print whitespace, as a general rule you ca
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign username = "John G. Chalmers-Smith" %}
{% if username and username.size > 10 %}
Wow, {{ username }} , you have a long name!
@@ -65,7 +65,7 @@ If you don't want any of your tags to print whitespace, as a general rule you ca
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign username = "John G. Chalmers-Smith" -%}
{%- if username and username.size > 10 -%}
Wow, {{ username -}} , you have a long name!

View File

@@ -8,7 +8,7 @@ Returns the absolute value of a number.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ -17 | abs }}
{{ 4 | abs }}
{% endraw %}
@@ -24,7 +24,7 @@ Returns the absolute value of a number.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "-19.86" | abs }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Adds the specified string to the end of another string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "/my/fancy/url" | append: ".html" }}
{% endraw %}
```
@@ -21,7 +21,7 @@ Adds the specified string to the end of another string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign filename = "/index.html" %}
{{ "website.com" | append: filename }}
{% endraw %}

View File

@@ -8,7 +8,7 @@ Limits a number to a minimum value.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 4 | at_least: 5 }}
{{ 4 | at_least: 3 }}
{% endraw %}

View File

@@ -8,7 +8,7 @@ Limits a number to a maximum value.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 4 | at_most: 5 }}
{{ 4 | at_most: 3 }}
{% endraw %}

View File

@@ -7,7 +7,7 @@ Makes the first character of a string capitalized and converts the remaining cha
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "title" | capitalize }}
{% endraw %}
```
@@ -21,7 +21,7 @@ Only the first character of a string is capitalized, so later words are not capi
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "my GREAT title" | capitalize }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Rounds an input up to the nearest whole number. Liquid tries to convert the inpu
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 1.2 | ceil }}
{{ 2.0 | ceil }}
{{ 183.357 | ceil }}
@@ -25,7 +25,7 @@ Here the input value is a string:
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "3.5" | ceil }}
{% endraw %}
```

View File

@@ -10,7 +10,7 @@ For this example, assume `site.pages` is an array of content pages for a website
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign site_categories = site.pages | map: "category" %}
{% for category in site_categories %}
@@ -34,7 +34,7 @@ By using `compact` when we create our `site_categories` array, we can remove all
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign site_categories = site.pages | map: "category" | compact %}
{% for category in site_categories %}

View File

@@ -8,7 +8,7 @@ Concatenates (joins together) multiple arrays. The resulting array contains all
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign fruits = "apples, oranges, peaches" | split: ", " %}
{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %}
@@ -34,7 +34,7 @@ You can string together multiple `concat` filters to join more than two arrays.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign furniture = "chairs, tables, shelves" | split: ", " %}
{% assign everything = fruits | concat: vegetables | concat: furniture %}

View File

@@ -7,7 +7,7 @@ Converts a timestamp into another date format. The format for this syntax is the
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ article.published_at | date: "%a, %b %d, %y" }}
{% endraw %}
```
@@ -19,7 +19,7 @@ Fri, Jul 17, 15
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ article.published_at | date: "%Y" }}
{% endraw %}
```
@@ -33,7 +33,7 @@ Fri, Jul 17, 15
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "March 14, 2016" | date: "%b %d, %y" }}
{% endraw %}
```
@@ -47,7 +47,7 @@ To get the current time, pass the special word `"now"` (or `"today"`) to `date`.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
{% endraw %}
```

View File

@@ -9,7 +9,7 @@ In this example, `product_price` is not defined, so the default value is used.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ product_price | default: 2.99 }}
{% endraw %}
```
@@ -23,7 +23,7 @@ In this example, `product_price` is defined, so the default value is not used.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign product_price = 4.99 %}
{{ product_price | default: 2.99 }}
{% endraw %}
@@ -39,7 +39,7 @@ In this example, `product_price` is empty, so the default value is used.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign product_price = "" %}
{{ product_price | default: 2.99 }}
{% endraw %}
@@ -57,7 +57,7 @@ To allow variables to return `false` instead of the default value, you can use t
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign display_price = false %}
{{ display_price | default: true, allow_false: true }}
{% endraw %}

View File

@@ -9,7 +9,7 @@ The result is rounded down to the nearest integer (that is, the [floor]({{ "/fil
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 16 | divided_by: 4 }}
{{ 5 | divided_by: 3 }}
{% endraw %}
@@ -29,7 +29,7 @@ For example, here the divisor is an integer:
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 20 | divided_by: 7 }}
{% endraw %}
```
@@ -43,7 +43,7 @@ Here it is a float:
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 20 | divided_by: 7.0 }}
{% endraw %}
```
@@ -61,7 +61,7 @@ In this example, we're dividing by a variable that contains an integer, so we ge
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_integer = 7 %}
{{ 20 | divided_by: my_integer }}
{% endraw %}
@@ -77,7 +77,7 @@ Here, we [multiply]({{ "/filters/times/" | prepend: site.baseurl }}) the variabl
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_integer = 7 %}
{% assign my_float = my_integer | times: 1.0 %}
{{ 20 | divided_by: my_float }}

View File

@@ -7,7 +7,7 @@ Makes each character in a string lowercase. It has no effect on strings which ar
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Parker Moore" | downcase }}
{% endraw %}
```
@@ -19,7 +19,7 @@ Makes each character in a string lowercase. It has no effect on strings which ar
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "apple" | downcase }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Escapes a string by replacing characters with escape sequences (so that the stri
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Have you read 'James & the Giant Peach'?" | escape }}
{% endraw %}
```
@@ -19,7 +19,7 @@ Escapes a string by replacing characters with escape sequences (so that the stri
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Tetsuro Takara" | escape }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Escapes a string without changing existing escaped entities. It doesn't change s
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "1 < 2 & 3" | escape_once }}
{% endraw %}
```
@@ -19,7 +19,7 @@ Escapes a string without changing existing escaped entities. It doesn't change s
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "1 &lt; 2 &amp; 3" | escape_once }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Returns the first item of an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | split: " " | first }}
{% endraw %}
```
@@ -19,7 +19,7 @@ Returns the first item of an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.first }}
@@ -36,7 +36,7 @@ Returns the first item of an array.
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 %}

View File

@@ -7,7 +7,7 @@ Rounds an input down to the nearest whole number. Liquid tries to convert the in
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 1.2 | floor }}
{{ 2.0 | floor }}
{{ 183.357 | floor }}
@@ -25,7 +25,7 @@ Here the input value is a string:
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "3.5" | floor }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Combines the items in an array into a single string using the argument as a sepa
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | join: " and " }}

View File

@@ -7,7 +7,7 @@ Returns the last item of an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | split: " " | last }}
{% endraw %}
```
@@ -19,7 +19,7 @@ Returns the last item of an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.last }}
@@ -36,7 +36,7 @@ Returns the last item of an array.
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 %}

View File

@@ -7,7 +7,7 @@ Removes all whitespace (tabs, spaces, and newlines) from the **left** side of a
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ " So much room for activities " | lstrip }}!
{% endraw %}
```

View File

@@ -9,7 +9,7 @@ In this example, assume the object `site.pages` contains all the metadata for a
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign all_categories = site.pages | map: "category" %}
{% for item in all_categories %}

View File

@@ -7,7 +7,7 @@ Subtracts a number from another number.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 4 | minus: 2 }}
{{ 16 | minus: 4 }}
{{ 183.357 | minus: 12 }}

View File

@@ -7,7 +7,7 @@ Returns the remainder of a division operation.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 3 | modulo: 2 }}
{{ 24 | modulo: 7 }}
{{ 183.357 | modulo: 12 }}

View File

@@ -7,7 +7,7 @@ Inserts an HTML line break (`<br />`) in front of each newline (`\n`) in a strin
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% capture string_with_newlines %}
Hello
there

View File

@@ -7,7 +7,7 @@ Adds a number to another number.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 4 | plus: 2 }}
{{ 16 | plus: 4 }}
{{ 183.357 | plus: 12 }}

View File

@@ -7,7 +7,7 @@ Adds the specified string to the beginning of another string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
{% endraw %}
```
@@ -21,7 +21,7 @@ Adds the specified string to the beginning of another string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign url = "example.com" %}
{{ "/index.html" | prepend: url }}
{% endraw %}

View File

@@ -7,7 +7,7 @@ Removes every occurrence of the specified substring from a string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "I strained to see the train through the rain" | remove: "rain" }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Removes only the first occurrence of the specified substring from a string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Replaces every occurrence of the first argument in a string with the second argu
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Replaces only the first occurrence of the first argument in a string with the se
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Reverses the order of the items in an array. `reverse` cannot reverse a string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | reverse | join: ", " }}
@@ -25,7 +25,7 @@ Although `reverse` cannot be used directly on a string, you can split a string i
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Rounds a number to the nearest integer or, if a number is passed as an argument,
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 1.2 | round }}
{{ 2.7 | round }}
{{ 183.357 | round: 2 }}

View File

@@ -7,7 +7,7 @@ Removes all whitespace (tabs, spaces, and newlines) from the **right** side of a
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ " So much room for activities " | rstrip }}!
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Returns the number of characters in a string or the number of items in an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | size }}
{% endraw %}
```
@@ -19,7 +19,7 @@ Returns the number of characters in a string or the number of items in an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.size }}
@@ -36,7 +36,7 @@ Returns the number of characters in a string or the number of items in an array.
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 %}

View File

@@ -9,7 +9,7 @@ String or array indices are numbered starting from 0.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Liquid" | slice: 0 }}
{% endraw %}
```
@@ -21,7 +21,7 @@ String or array indices are numbered starting from 0.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Liquid" | slice: 2 }}
{% endraw %}
```
@@ -33,7 +33,7 @@ String or array indices are numbered starting from 0.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Liquid" | slice: 2, 5 }}
{% endraw %}
```
@@ -47,7 +47,7 @@ Here the input value is an array:
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | slice: 1, 2 }}
{% endraw %}
@@ -63,7 +63,7 @@ If the first argument is a negative number, the indices are counted from the end
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Liquid" | slice: -3, 2 }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Sorts items in an array in case-sensitive order.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort | join: ", " }}
@@ -24,7 +24,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 %}
<h4>{{ product.title }}</h4>

View File

@@ -8,7 +8,7 @@ Sorts items in an array in case-insensitive order.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort_natural | join: ", " }}
@@ -25,7 +25,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 %}
<h4>{{ product.title }}</h4>

View File

@@ -7,7 +7,7 @@ Divides a string into an array using the argument as a separator. `split` is com
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{% for member in beatles %}

View File

@@ -7,7 +7,7 @@ Removes all whitespace (tabs, spaces, and newlines) from both the left and right
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ " So much room for activities " | strip }}!
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Removes any HTML tags from a string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Removes any newline characters (line breaks) from a string.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% capture string_with_newlines %}
Hello
there

View File

@@ -7,7 +7,7 @@ Multiplies a number by another number.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ 3 | times: 2 }}
{{ 24 | times: 7 }}
{{ 183.357 | times: 12 }}

View File

@@ -7,7 +7,7 @@ Shortens a string down to the number of characters passed as an argument. If the
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | truncate: 20 }}
{% endraw %}
```
@@ -25,7 +25,7 @@ The length of the second argument counts against the number of characters specif
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
{% endraw %}
```
@@ -41,7 +41,7 @@ You can truncate to the exact number of characters specified by the first argume
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | truncate: 20, "" }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Shortens a string down to the number of words passed as an argument. If the spec
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | truncatewords: 3 }}
{% endraw %}
```
@@ -23,7 +23,7 @@ Shortens a string down to the number of words passed as an argument. If the spec
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
{% endraw %}
```
@@ -39,7 +39,7 @@ You can avoid showing trailing characters by passing a blank string as the secon
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Removes any duplicate items in an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
{{ my_array | uniq | join: ", " }}

View File

@@ -7,7 +7,7 @@ Makes each character in a string uppercase. It has no effect on strings which ar
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Parker Moore" | upcase }}
{% endraw %}
```
@@ -19,7 +19,7 @@ Makes each character in a string uppercase. It has no effect on strings which ar
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "APPLE" | upcase }}
{% endraw %}
```

View File

@@ -8,7 +8,7 @@ Decodes a string that has been encoded as a URL or by [`url_encode`]({{ "/filter
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "%27Stop%21%27+said+Fred" | url_decode }}
{% endraw %}
```

View File

@@ -7,7 +7,7 @@ Converts any URL-unsafe characters in a string into percent-encoded characters.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "john@liquid.com" | url_encode }}
{% endraw %}
```
@@ -21,7 +21,7 @@ Note that `url_encode` will turn a space into a `+` sign instead of a percent-en
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{{ "Tetsuro Takara" | url_encode }}
{% endraw %}
```

View File

@@ -10,7 +10,7 @@ In this example, assume you have a list of products and you want to show your ki
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
All products:
{% for product in products %}
- {{ product.title }}
@@ -42,7 +42,7 @@ Say instead you have a list of products and you only want to show those that are
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
All products:
{% for product in products %}
- {{ product.title }}
@@ -73,7 +73,7 @@ The `where` filter can also be used to find a single object in an array when com
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign new_shirt = products | where: "type", "shirt" | first %}
Featured product: {{ new_shirt.title }}

View File

@@ -12,7 +12,7 @@ Executes a block of code only if a certain condition is `true`.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% if product.title == "Awesome Shoes" %}
These shoes are awesome!
{% endif %}
@@ -30,7 +30,7 @@ The opposite of `if` executes a block of code only if a certain condition is
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% unless product.title == "Awesome Shoes" %}
These shoes are not awesome.
{% endunless %}
@@ -45,7 +45,7 @@ These shoes are not awesome.
This would be the equivalent of doing the following:
```liquid
{% raw %}
{%- raw -%}
{% if product.title != "Awesome Shoes" %}
These shoes are not awesome.
{% endif %}
@@ -58,7 +58,7 @@ Adds more conditions within an `if` or `unless` block.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
<!-- If customer.name = "anonymous" -->
{% if customer.name == "kevin" %}
Hey Kevin!
@@ -83,7 +83,7 @@ An optional `else` statement at the end of the case provides code to execute if
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign handle = "cake" %}
{% case handle %}
{% when "cake" %}

View File

@@ -11,7 +11,7 @@ Repeatedly executes a block of code. For a full list of attributes available wit
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% for product in collection.products %}
{{ product.title }}
{% endfor %}
@@ -29,7 +29,7 @@ Specifies a fallback case for a `for` loop which will run if the loop has zero l
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% for product in collection.products %}
{{ product.title }}
{% else %}
@@ -49,7 +49,7 @@ Causes the loop to stop iterating when it encounters the `break` tag.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% for i in (1..5) %}
{% if i == 4 %}
{% break %}
@@ -71,7 +71,7 @@ Causes the loop to skip the current iteration when it encounters the `continue`
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% for i in (1..5) %}
{% if i == 4 %}
{% continue %}
@@ -95,7 +95,7 @@ Limits the loop to the specified number of iterations.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
<!-- if array = [1,2,3,4,5,6] -->
{% for item in array limit:2 %}
{{ item }}
@@ -114,7 +114,7 @@ Begins the loop at the specified index.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
<!-- if array = [1,2,3,4,5,6] -->
{% for item in array offset:2 %}
{{ item }}
@@ -131,7 +131,7 @@ To start a loop from where the last loop using the same iterator left off, pass
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
<!-- if array = [1,2,3,4,5,6] -->
{% for item in array limit: 3 %}
{{ item }}
@@ -154,7 +154,7 @@ Defines a range of numbers to loop through. The range can be defined by both lit
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% for i in (3..5) %}
{{ i }}
{% endfor %}
@@ -179,7 +179,7 @@ Reverses the order of the loop. Note that this flag's spelling is different from
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
<!-- if array = [1,2,3,4,5,6] -->
{% for item in array reversed %}
{{ item }}
@@ -200,7 +200,7 @@ Loops through a group of strings and prints them in the order that they were pas
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %}
@@ -227,7 +227,7 @@ Uses for `cycle` include:
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% cycle "first": "one", "two", "three" %}
{% cycle "second": "one", "two", "three" %}
{% cycle "second": "one", "two", "three" %}
@@ -249,7 +249,7 @@ Generates an HTML table. Must be wrapped in opening `<table>` and closing `</tab
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
<table>
{% tablerow product in collection.products %}
{{ product.title }}
@@ -292,7 +292,7 @@ Defines how many columns the tables should have.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% tablerow product in collection.products cols:2 %}
{{ product.title }}
{% endtablerow %}
@@ -334,7 +334,7 @@ Defines how many columns the tables should have.
Exits the `tablerow` loop after a specific index.
```liquid
{% raw %}
{%- raw -%}
{% tablerow product in collection.products cols:2 limit:3 %}
{{ product.title }}
{% endtablerow %}
@@ -346,7 +346,7 @@ Exits the `tablerow` loop after a specific index.
Starts the `tablerow` loop after a specific index.
```liquid
{% raw %}
{%- raw -%}
{% tablerow product in collection.products cols:2 offset:3 %}
{{ product.title }}
{% endtablerow %}
@@ -358,7 +358,7 @@ Starts the `tablerow` loop after a specific index.
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.
```liquid
{% raw %}
{%- raw -%}
<!--variable number example-->
{% assign num = 4 %}

View File

@@ -14,7 +14,7 @@ Allows you to leave un-rendered code inside a Liquid template. Any text within t
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign verb = "turned" %}
{% comment %}
{% assign verb = "converted" %}
@@ -57,7 +57,7 @@ In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not.
Encloses multiple tags within one set of delimiters, to allow writing Liquid logic more concisely.
```liquid
{% raw %}
{%- raw -%}
{% liquid
case section.blocks.size
when 1
@@ -80,7 +80,7 @@ Outputs an expression in the rendered HTML. This is identical to wrapping an exp
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% liquid
for product in collection.products
echo product.title | capitalize
@@ -98,7 +98,7 @@ Hat Shirt Pants
Insert the rendered content of another template within the current template.
```liquid
{% raw %}
{%- raw -%}
{% render "template-name" %}
{% endraw %}
```
@@ -112,7 +112,7 @@ The code within the rendered template does **not** automatically have access to
Variables assigned using [variable tags]({{ "/tags/variable/" | prepend: site.baseurl }}) can be passed to a template by listing them as parameters on the `render` tag.
```liquid
{% raw %}
{%- raw -%}
{% assign my_variable = "apples" %}
{% render "name", my_variable: my_variable, my_other_variable: "oranges" %}
{% endraw %}
@@ -121,7 +121,7 @@ Variables assigned using [variable tags]({{ "/tags/variable/" | prepend: site.ba
One or more objects can be passed to a template.
```liquid
{% raw %}
{%- raw -%}
{% assign featured_product = all_products["product_handle"] %}
{% render "product", product: featured_product %}
{% endraw %}
@@ -132,7 +132,7 @@ One or more objects can be passed to a template.
A single object can be passed to a template by using the `with` and optional `as` parameters.
```liquid
{% raw %}
{%- raw -%}
{% assign featured_product = all_products["product_handle"] %}
{% render "product" with featured_product as product %}
{% endraw %}
@@ -145,7 +145,7 @@ In the example above, the `product` variable in the rendered template will hold
A template can be rendered once for each value of an enumerable object by using the `for` and optional `as` parameters.
```liquid
{% raw %}
{%- raw -%}
{% assign variants = product.variants %}
{% render "product_variant" for variants as variant %}
{% endraw %}
@@ -162,7 +162,7 @@ _The `include` tag is deprecated; please use [`render`](#render) instead._
Insert the rendered content of another template within the current template.
```liquid
{% raw %}
{%- raw -%}
{% include "template-name" %}
{% endraw %}
```

View File

@@ -11,7 +11,7 @@ Creates a new named variable.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign my_variable = false %}
{% if my_variable != true %}
This statement is valid.
@@ -28,7 +28,7 @@ Wrap a value in quotations `"` to save it as a string variable.
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign foo = "bar" %}
{{ foo }}
{% endraw %}
@@ -46,7 +46,7 @@ Captures the string inside of the opening and closing tags and assigns it to a v
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% capture my_variable %}I am being captured.{% endcapture %}
{{ my_variable }}
{% endraw %}
@@ -61,7 +61,7 @@ Using `capture`, you can create complex strings using other variables created wi
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign favorite_food = "pizza" %}
{% assign age = 35 %}
@@ -84,7 +84,7 @@ Creates and outputs a new number variable with initial value `0`. On subsequent
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% increment my_counter %}
{% increment my_counter %}
{% increment my_counter %}
@@ -104,7 +104,7 @@ In the example below, a variable named "var" is created using `assign`. The `inc
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% assign var = 10 %}
{% increment var %}
{% increment var %}
@@ -128,7 +128,7 @@ Creates and outputs a new number variable with initial value `-1`. On subsequent
<p class="code-label">Input</p>
```liquid
{% raw %}
{%- raw -%}
{% decrement variable %}
{% decrement variable %}
{% decrement variable %}