mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Grammar and word choice improvements for readability
This commit is contained in:
@@ -5,7 +5,7 @@ description: An overview of controlling whitespace between code in the Liquid te
|
||||
|
||||
In Liquid, you can include a hyphen in your tag syntax `{% raw %}{{-{% endraw %}`, `{% raw %}-}}{% endraw %}`, `{% raw %}{%-{% endraw %}`, and `{% raw %}-%}{% endraw %}` to strip whitespace from the left or right side of a rendered tag.
|
||||
|
||||
Normally, even if it doesn't output text, any line of Liquid in your template will still output a blank line in your rendered HTML:
|
||||
Normally, even if it doesn't print text, any line of Liquid in your template will still print a blank line in your rendered HTML:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
@@ -38,7 +38,7 @@ By including hyphens in your `assign` tag, you can strip the generated whitespac
|
||||
tomato
|
||||
```
|
||||
|
||||
If you don't want any of your tags to output whitespace, as a general rule you can add hyphens to both sides of all your tags (`{% raw %}{%-{% endraw %}` and `{% raw %}-%}{% endraw %}`):
|
||||
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 %}`):
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: abs
|
||||
description: Liquid filter that gets the absolute value of a number.
|
||||
description: Liquid filter that returns the absolute value of a number.
|
||||
redirect_from: /filters/
|
||||
---
|
||||
|
||||
@@ -30,7 +30,7 @@ Returns the absolute value of a number.
|
||||
{{ 4 | abs }}
|
||||
```
|
||||
|
||||
`abs` will also work on a string if the string only contains a number.
|
||||
`abs` will also work on a string that only contains a number:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: at_least
|
||||
description: Liquid filter that limits a number to a minimum value
|
||||
description: Liquid filter that limits a number to a minimum value.
|
||||
---
|
||||
|
||||
Limits a number to a minimum value.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: at_most
|
||||
description: Liquid filter that limits a number to a maximum value
|
||||
description: Liquid filter that limits a number to a maximum value.
|
||||
---
|
||||
|
||||
Limits a number to a maximum value.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: capitalize
|
||||
description: Liquid filter that capitalizes the first character in a string.
|
||||
description: Liquid filter that capitalizes the first character of a string.
|
||||
---
|
||||
|
||||
Makes the first character of a string capitalized.
|
||||
@@ -17,7 +17,7 @@ Makes the first character of a string capitalized.
|
||||
{{ "title" | capitalize }}
|
||||
```
|
||||
|
||||
`capitalize` only capitalizes the first character of the string, so later words are not affected:
|
||||
`capitalize` only capitalizes the first character of a string, so later words are not affected:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: ceil
|
||||
description: Liquid filter that gets the ceiling of a number by rounding up to the nearest integer.
|
||||
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.
|
||||
|
||||
@@ -3,7 +3,7 @@ title: divided_by
|
||||
description: Liquid filter that divides a number by another number.
|
||||
---
|
||||
|
||||
Divides a number by the specified number.
|
||||
Divides a number by another number.
|
||||
|
||||
The result is rounded down to the nearest integer (that is, the [floor]({{ "/filters/floor/" | prepend: site.baseurl }})) if the divisor is an integer.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: downcase
|
||||
description: Liquid filter that coverts a string to lowercase.
|
||||
description: Liquid filter that converts a string to lowercase.
|
||||
---
|
||||
|
||||
Makes each character in a string lowercase. It has no effect on strings which are already all lowercase.
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ Returns the first item of an array.
|
||||
{{ my_array.first }}
|
||||
```
|
||||
|
||||
You can use `first` with dot notation when you need to use the filter inside a tag.
|
||||
You can use `first` with dot notation when you need to use the filter inside a tag:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: floor
|
||||
description: Liquid filter that gets the floor of a number by rounding down to the nearest integer.
|
||||
description: Liquid filter that returns the floor of a number by rounding down to the nearest integer.
|
||||
---
|
||||
|
||||
Rounds a number down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
|
||||
Rounds the input down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: last
|
||||
description: Liquid filter that gets the last value in an array.
|
||||
description: Liquid filter that returns the last item of an array.
|
||||
---
|
||||
|
||||
Returns the last item of an array.
|
||||
@@ -33,7 +33,7 @@ Returns the last item of an array.
|
||||
{{ my_array.last }}
|
||||
```
|
||||
|
||||
You can use `last` with dot notation when you need to use the filter inside a tag.
|
||||
You can use `last` with dot notation when you need to use the filter inside a tag:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: lstrip
|
||||
description: Liquid filter that removes whitespace from the left side of a string.
|
||||
description: Liquid filter that removes all whitespace from the left side of a string.
|
||||
---
|
||||
|
||||
Removes all whitespaces (tabs, spaces, and newlines) from the beginning of a string. The filter 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.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: minus
|
||||
description: Liquid filter that subtracts one number from another.
|
||||
description: Liquid filter that subtracts one number from another number.
|
||||
---
|
||||
|
||||
Subtracts a number from another number.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: modulo
|
||||
description: Liquid filter that returns the remainder from a division operation.
|
||||
description: Liquid filter that returns the remainder of a division operation.
|
||||
---
|
||||
|
||||
Returns the remainder of a division operation.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: newline_to_br
|
||||
description: Liquid filter that converts newlines in an input string to HTML <br> tags.
|
||||
description: Liquid filter that converts newlines in a string to HTML <br /> tags.
|
||||
---
|
||||
|
||||
Replaces every newline (`\n`) with an HTML line break (`<br>`).
|
||||
Replaces every newline (`\n`) in a string with an HTML line break (`<br />`).
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: plus
|
||||
description: Liquid filter that adds a number to another number.
|
||||
description: Liquid filter that adds one number to another number.
|
||||
---
|
||||
|
||||
Adds a number to another number.
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ Adds the specified string to the beginning of another string.
|
||||
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
|
||||
```
|
||||
|
||||
You can also `prepend` variables:
|
||||
`prepend` can also be used with variables:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ title: replace
|
||||
description: Liquid filter that replaces all occurences of a given substring in a string.
|
||||
---
|
||||
|
||||
Replaces every occurrence of an argument in a string with the second argument.
|
||||
Replaces every occurrence of the first argument in a string with the second argument.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ Reverses the order of the items in an array. `reverse` cannot reverse a string.
|
||||
{{ my_array | reverse | join: ", " }}
|
||||
```
|
||||
|
||||
`reverse` cannot be used directly on a string, but you can split a string into an array, reverse the array, and rejoin it by chaining together filters:
|
||||
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:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ title: round
|
||||
description: Liquid filter that rounds a number to the nearest integer.
|
||||
---
|
||||
|
||||
Rounds an input number to the nearest integer or, if a number is specified as an argument, to that number of decimal places.
|
||||
Rounds a number to the nearest integer or, if a number is passed as an argument, to that number of decimal places.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ title: rstrip
|
||||
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.
|
||||
Removes all whitespace (tabs, spaces, and newlines) from the right side of a string. It does not affect spaces between words.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ Returns the number of characters in a string or the number of items in an array.
|
||||
{{ my_array.size }}
|
||||
```
|
||||
|
||||
You can use `size` with dot notation when you need to use the filter inside a tag.
|
||||
You can use `size` with dot notation when you need to use the filter inside a tag:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ title: slice
|
||||
description: Liquid filter that returns a substring from a given position in a string.
|
||||
---
|
||||
|
||||
Returns a substring of 1 character beginning at the index specified by the argument passed in. An optional second argument specifies the length of the substring to be returned.
|
||||
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.
|
||||
|
||||
String indices are numbered starting from 0.
|
||||
|
||||
@@ -43,7 +43,7 @@ String indices are numbered starting from 0.
|
||||
{{ "Liquid" | slice: 2, 5 }}
|
||||
```
|
||||
|
||||
If the first parameter is a negative number, the indices are counted from the end of the string:
|
||||
If the first argument is a negative number, the indices are counted from the end of the string:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ Sorts items in an array in case-sensitive order.
|
||||
{{ my_array | sort | join: ", " }}
|
||||
```
|
||||
|
||||
An optional parameter specifies which property of the array's items to use for sorting.
|
||||
An optional argument specifies which property of the array's items to use for sorting.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
|
||||
@@ -21,7 +21,7 @@ Sorts items in an array in case-insensitive order.
|
||||
{{ my_array | sort_natural | join: ", " }}
|
||||
```
|
||||
|
||||
An optional parameter specifies which property of the array's items to use for sorting.
|
||||
An optional argument specifies which property of the array's items to use for sorting.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ title: split
|
||||
description: Liquid filter that splits a string into an array using separators.
|
||||
---
|
||||
|
||||
Divides an input string into an array using the argument as a separator. `split` is commonly used to convert comma-separated items from a string to an array.
|
||||
Divides a string into an array using the argument as a separator. `split` is commonly used to convert comma-separated items from a string to an array.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: strip
|
||||
description: Liquid filter that removes whitespace from the left and right sides of a string.
|
||||
description: Liquid filter that removes all whitespace from the left and right sides of a string.
|
||||
---
|
||||
|
||||
Removes all whitespace (tabs, spaces, and newlines) from both the left and right side of a string. It does not affect spaces between words.
|
||||
Removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
@@ -3,7 +3,7 @@ title: truncate
|
||||
description: Liquid filter that truncates a string to a given number of characters.
|
||||
---
|
||||
|
||||
`truncate` shortens a string down to the number of characters passed as a parameter. If the number of characters specified is less than the length of the string, an ellipsis (...) is appended to the string and is included in the character count.
|
||||
Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (...) is appended to the string and is included in the character count.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
@@ -19,9 +19,9 @@ description: Liquid filter that truncates a string to a given number of characte
|
||||
|
||||
### Custom ellipsis
|
||||
|
||||
`truncate` takes an optional second parameter 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.
|
||||
`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 parameter counts against the number of characters specified by the first parameter. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use **13** for the first parameter of `truncate`, since the ellipsis counts as 3 characters.
|
||||
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.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
@@ -37,7 +37,7 @@ The length of the second parameter counts against the number of characters speci
|
||||
|
||||
### No ellipsis
|
||||
|
||||
You can truncate to the exact number of characters specified by the first parameter and show no trailing characters by passing a blank string as the second parameter:
|
||||
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:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: truncatewords
|
||||
description: Liquid filter that truncates a string to the given number of words.
|
||||
description: Liquid filter that truncates a string to a given number of words.
|
||||
---
|
||||
|
||||
Shortens a string down to the number of words passed as the argument. If the specified number of words is less than the number of words in the string, an ellipsis (...) is appended to the string.
|
||||
Shortens a string down to the number of words passed as an argument. If the specified number of words is less than the number of words in the string, an ellipsis (...) is appended to the string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
@@ -19,7 +19,7 @@ Shortens a string down to the number of words passed as the argument. If the spe
|
||||
|
||||
### Custom ellipsis
|
||||
|
||||
`truncatewords` takes an optional second parameter 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.
|
||||
`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.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
@@ -35,7 +35,7 @@ Shortens a string down to the number of words passed as the argument. If the spe
|
||||
|
||||
### No ellipsis
|
||||
|
||||
You can avoid showing trailing characters by passing a blank string as the second parameter:
|
||||
You can avoid showing trailing characters by passing a blank string as the second argument:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: upcase
|
||||
description: Liquid filter that capitalizes every character in a string.
|
||||
description: Liquid filter that converts a string to uppercase.
|
||||
---
|
||||
|
||||
Makes each character in a string uppercase. It has no effect on strings which are already all uppercase.
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ description: An overview of comments tags in the Liquid template language.
|
||||
---
|
||||
|
||||
Allows you to leave un-rendered code inside a Liquid template. Any text within
|
||||
the opening and closing `comment` blocks will not be output, and any Liquid code
|
||||
the opening and closing `comment` blocks will not be printed, and any Liquid code
|
||||
within will not be executed.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
|
||||
+3
-3
@@ -153,7 +153,7 @@ Defines a range of numbers to loop through. The range can be defined by both lit
|
||||
|
||||
### reversed
|
||||
|
||||
Reverses the order of the loop. Note that the flag’s spelling is different to the filter `reverse`.
|
||||
Reverses the order of the loop. Note that this flag's spelling is different from the filter `reverse`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
@@ -172,7 +172,7 @@ Reverses the order of the loop. Note that the flag’s spelling is different to
|
||||
|
||||
## cycle
|
||||
|
||||
Loops through a group of strings and outputs them in the order that they were passed as parameters. Each time `cycle` is called, the next string that was passed as a parameter is output.
|
||||
Loops through a group of strings and prints them in the order that they were passed as arguments. Each time `cycle` is called, the next string argument is printed.
|
||||
|
||||
`cycle` must be used within a [for](#for) loop block.
|
||||
|
||||
@@ -201,7 +201,7 @@ Uses for `cycle` include:
|
||||
|
||||
## cycle (parameters)
|
||||
|
||||
`cycle` accepts a parameter called `cycle group` in cases where you need multiple `cycle` blocks in one template. If no name is supplied for the cycle group, then it is assumed that multiple calls with the same parameters are one group.
|
||||
`cycle` accepts a "cycle group" parameter in cases where you need multiple `cycle` blocks in one template. If no name is supplied for the cycle group, then it is assumed that multiple calls with the same parameters are one group.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ Creates a new variable.
|
||||
This statement is valid.
|
||||
```
|
||||
|
||||
Wrap a variable in quotations `"` to save it as a string.
|
||||
Wrap a variable value in quotations `"` to save it as a string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
@@ -41,7 +41,7 @@ bar
|
||||
|
||||
## capture
|
||||
|
||||
Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created through `{% raw %}{% capture %}{% endraw %}` are strings.
|
||||
Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created through `capture` are strings.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
@@ -56,7 +56,7 @@ Captures the string inside of the opening and closing tags and assigns it to a v
|
||||
I am being captured.
|
||||
```
|
||||
|
||||
Using `capture`, you can create complex strings using other variables created with `assign`.
|
||||
Using `capture`, you can create complex strings using other variables created with `assign`:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
|
||||
Reference in New Issue
Block a user