Drop blank lines from input examples

This commit is contained in:
EricFromCanada
2021-04-28 13:43:02 -04:00
parent 77c2dfa989
commit b98d3d6097
57 changed files with 152 additions and 152 deletions
+4 -4
View File
@@ -12,7 +12,7 @@ Liquid uses a combination of [**objects**](#objects), [**tags**](#tags), and [**
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ page.title }} {{ page.title }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% if user %} {% if user %}
Hello {{ user.name }}! Hello {{ user.name }}!
{% endif %} {% endif %}
@@ -57,7 +57,7 @@ You can read more about each type of tag in their respective sections.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "/my/fancy/url" | append: ".html" }} {{ "/my/fancy/url" | append: ".html" }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "adam!" | capitalize | prepend: "Hello " }} {{ "adam!" | capitalize | prepend: "Hello " }}
{% endraw %} {% endraw %}
``` ```
+6 -6
View File
@@ -47,7 +47,7 @@ Liquid includes many logical and comparison operators. You can use operators to
For example: For example:
```liquid ```liquid
{% raw %} {%- raw -%}
{% if product.title == "Awesome Shoes" %} {% if product.title == "Awesome Shoes" %}
These shoes are awesome! These shoes are awesome!
{% endif %} {% endif %}
@@ -57,7 +57,7 @@ For example:
You can do multiple comparisons in a tag using the `and` and `or` operators: You can do multiple comparisons in a tag using the `and` and `or` operators:
```liquid ```liquid
{% raw %} {%- raw -%}
{% if product.type == "Shirt" or product.type == "Shoes" %} {% if product.type == "Shirt" or product.type == "Shoes" %}
This is a shirt or a pair of shoes. This is a shirt or a pair of shoes.
{% endif %} {% 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. `contains` checks for the presence of a substring inside a string.
```liquid ```liquid
{% raw %} {%- raw -%}
{% if product.title contains "Pack" %} {% if product.title contains "Pack" %}
This product's title contains the word Pack. This product's title contains the word Pack.
{% endif %} {% 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. `contains` can also check for the presence of a string in an array of strings.
```liquid ```liquid
{% raw %} {%- raw -%}
{% if product.tags contains "Hello" %} {% if product.tags contains "Hello" %}
This product has been tagged with "Hello". This product has been tagged with "Hello".
{% endif %} {% 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. 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 ```liquid
{% raw %} {%- raw -%}
{% if true or false and false %} {% if true or false and false %}
This evaluates to true, since the `and` condition is checked first. This evaluates to true, since the `and` condition is checked first.
{% endif %} {% endif %}
@@ -101,7 +101,7 @@ In tags with more than one `and` or `or` operator, operators are checked in orde
``` ```
```liquid ```liquid
{% raw %} {%- raw -%}
{% if true and false and false or true %} {% if true and false and false or true %}
This evaluates to false, since the tags are checked like this: This evaluates to false, since the tags are checked like this:
+2 -2
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: In the example below, the text "Tobi" is not a boolean, but it is truthy in a conditional:
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign name = "Tobi" %} {% assign name = "Tobi" %}
{% if name %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% if page.category %} {% if page.category %}
<h1>{{ page.category }}</h1> <h1>{{ page.category }}</h1>
{% endif %} {% endif %}
+9 -9
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: Strings are sequences of characters wrapped in single or double quotes:
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_string = "Hello World!" %} {% assign my_string = "Hello World!" %}
{% endraw %} {% endraw %}
``` ```
@@ -31,7 +31,7 @@ Liquid does not convert escape sequences into special characters.
Numbers include floats and integers: Numbers include floats and integers:
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_int = 25 %} {% assign my_int = 25 %}
{% assign my_float = -39.756 %} {% assign my_float = -39.756 %}
{% endraw %} {% endraw %}
@@ -42,7 +42,7 @@ Numbers include floats and integers:
Booleans are either `true` or `false`. No quotations are necessary when declaring a boolean: Booleans are either `true` or `false`. No quotations are necessary when declaring a boolean:
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign foo = true %} {% assign foo = true %}
{% assign bar = false %} {% assign bar = false %}
{% endraw %} {% 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: In the following example, if the user does not exist (that is, `user` returns `nil`), Liquid will not print the greeting:
```liquid ```liquid
{% raw %} {%- raw -%}
{% if user %} {% if user %}
Hello {{ user.name }}! Hello {{ user.name }}!
{% endif %} {% endif %}
@@ -68,7 +68,7 @@ Tags or outputs that return `nil` will not print anything to the page.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
The current user is {{ user.name }} The current user is {{ user.name }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" --> <!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
{% for user in site.users %} {% for user in site.users %}
{{ user }} {{ 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" --> <!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
{{ site.users[0] }} {{ site.users[0] }}
{{ site.users[1] }} {{ 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: 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 ```liquid
{% raw %} {%- raw -%}
{% assign variable = "hello" %} {% assign variable = "hello" %}
{% assign page_1 = pages[variable] %} {% assign page_1 = pages[variable] %}
{% assign page_2 = pages["does-not-exist"] %} {% 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. You can check to see if an object exists or not before you access any of its attributes.
```liquid ```liquid
{% raw %} {%- raw -%}
{% unless pages == empty %} {% unless pages == empty %}
<h1>{{ pages.frontpage.title }}</h1> <h1>{{ pages.frontpage.title }}</h1>
<div>{{ pages.frontpage.content }}</div> <div>{{ pages.frontpage.content }}</div>
+4 -4
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_variable = "tomato" %} {% assign my_variable = "tomato" %}
{{ my_variable }} {{ my_variable }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_variable = "tomato" -%} {% assign my_variable = "tomato" -%}
{{ my_variable }} {{ my_variable }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign username = "John G. Chalmers-Smith" %} {% assign username = "John G. Chalmers-Smith" %}
{% if username and username.size > 10 %} {% if username and username.size > 10 %}
Wow, {{ username }} , you have a long name! 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign username = "John G. Chalmers-Smith" -%} {% assign username = "John G. Chalmers-Smith" -%}
{%- if username and username.size > 10 -%} {%- if username and username.size > 10 -%}
Wow, {{ username -}} , you have a long name! Wow, {{ username -}} , you have a long name!
+2 -2
View File
@@ -8,7 +8,7 @@ Returns the absolute value of a number.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ -17 | abs }} {{ -17 | abs }}
{{ 4 | abs }} {{ 4 | abs }}
{% endraw %} {% endraw %}
@@ -24,7 +24,7 @@ Returns the absolute value of a number.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "-19.86" | abs }} {{ "-19.86" | abs }}
{% endraw %} {% endraw %}
``` ```
+2 -2
View File
@@ -7,7 +7,7 @@ Adds the specified string to the end of another string.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "/my/fancy/url" | append: ".html" }} {{ "/my/fancy/url" | append: ".html" }}
{% endraw %} {% endraw %}
``` ```
@@ -21,7 +21,7 @@ Adds the specified string to the end of another string.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign filename = "/index.html" %} {% assign filename = "/index.html" %}
{{ "website.com" | append: filename }} {{ "website.com" | append: filename }}
{% endraw %} {% endraw %}
+1 -1
View File
@@ -8,7 +8,7 @@ Limits a number to a minimum value.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 4 | at_least: 5 }} {{ 4 | at_least: 5 }}
{{ 4 | at_least: 3 }} {{ 4 | at_least: 3 }}
{% endraw %} {% endraw %}
+1 -1
View File
@@ -8,7 +8,7 @@ Limits a number to a maximum value.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 4 | at_most: 5 }} {{ 4 | at_most: 5 }}
{{ 4 | at_most: 3 }} {{ 4 | at_most: 3 }}
{% endraw %} {% endraw %}
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "title" | capitalize }} {{ "title" | capitalize }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "my GREAT title" | capitalize }} {{ "my GREAT title" | capitalize }}
{% endraw %} {% endraw %}
``` ```
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 1.2 | ceil }} {{ 1.2 | ceil }}
{{ 2.0 | ceil }} {{ 2.0 | ceil }}
{{ 183.357 | ceil }} {{ 183.357 | ceil }}
@@ -25,7 +25,7 @@ Here the input value is a string:
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "3.5" | ceil }} {{ "3.5" | ceil }}
{% endraw %} {% endraw %}
``` ```
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign site_categories = site.pages | map: "category" %} {% assign site_categories = site.pages | map: "category" %}
{% for category in site_categories %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign site_categories = site.pages | map: "category" | compact %} {% assign site_categories = site.pages | map: "category" | compact %}
{% for category in site_categories %} {% for category in site_categories %}
+2 -2
View File
@@ -8,7 +8,7 @@ Concatenates (joins together) multiple arrays. The resulting array contains all
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign fruits = "apples, oranges, peaches" | split: ", " %} {% assign fruits = "apples, oranges, peaches" | split: ", " %}
{% assign vegetables = "carrots, turnips, potatoes" | 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign furniture = "chairs, tables, shelves" | split: ", " %} {% assign furniture = "chairs, tables, shelves" | split: ", " %}
{% assign everything = fruits | concat: vegetables | concat: furniture %} {% assign everything = fruits | concat: vegetables | concat: furniture %}
+4 -4
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ article.published_at | date: "%a, %b %d, %y" }} {{ article.published_at | date: "%a, %b %d, %y" }}
{% endraw %} {% endraw %}
``` ```
@@ -19,7 +19,7 @@ Fri, Jul 17, 15
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ article.published_at | date: "%Y" }} {{ article.published_at | date: "%Y" }}
{% endraw %} {% endraw %}
``` ```
@@ -33,7 +33,7 @@ Fri, Jul 17, 15
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "March 14, 2016" | date: "%b %d, %y" }} {{ "March 14, 2016" | date: "%b %d, %y" }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}. This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
{% endraw %} {% endraw %}
``` ```
+4 -4
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ product_price | default: 2.99 }} {{ product_price | default: 2.99 }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign product_price = 4.99 %} {% assign product_price = 4.99 %}
{{ product_price | default: 2.99 }} {{ product_price | default: 2.99 }}
{% endraw %} {% endraw %}
@@ -39,7 +39,7 @@ In this example, `product_price` is empty, so the default value is used.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign product_price = "" %} {% assign product_price = "" %}
{{ product_price | default: 2.99 }} {{ product_price | default: 2.99 }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign display_price = false %} {% assign display_price = false %}
{{ display_price | default: true, allow_false: true }} {{ display_price | default: true, allow_false: true }}
{% endraw %} {% endraw %}
+5 -5
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 16 | divided_by: 4 }} {{ 16 | divided_by: 4 }}
{{ 5 | divided_by: 3 }} {{ 5 | divided_by: 3 }}
{% endraw %} {% endraw %}
@@ -29,7 +29,7 @@ For example, here the divisor is an integer:
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 20 | divided_by: 7 }} {{ 20 | divided_by: 7 }}
{% endraw %} {% endraw %}
``` ```
@@ -43,7 +43,7 @@ Here it is a float:
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 20 | divided_by: 7.0 }} {{ 20 | divided_by: 7.0 }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_integer = 7 %} {% assign my_integer = 7 %}
{{ 20 | divided_by: my_integer }} {{ 20 | divided_by: my_integer }}
{% endraw %} {% endraw %}
@@ -77,7 +77,7 @@ Here, we [multiply]({{ "/filters/times/" | prepend: site.baseurl }}) the variabl
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_integer = 7 %} {% assign my_integer = 7 %}
{% assign my_float = my_integer | times: 1.0 %} {% assign my_float = my_integer | times: 1.0 %}
{{ 20 | divided_by: my_float }} {{ 20 | divided_by: my_float }}
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Parker Moore" | downcase }} {{ "Parker Moore" | downcase }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "apple" | downcase }} {{ "apple" | downcase }}
{% endraw %} {% endraw %}
``` ```
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Have you read 'James & the Giant Peach'?" | escape }} {{ "Have you read 'James & the Giant Peach'?" | escape }}
{% endraw %} {% endraw %}
``` ```
@@ -19,7 +19,7 @@ Escapes a string by replacing characters with escape sequences (so that the stri
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Tetsuro Takara" | escape }} {{ "Tetsuro Takara" | escape }}
{% endraw %} {% endraw %}
``` ```
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "1 < 2 & 3" | escape_once }} {{ "1 < 2 & 3" | escape_once }}
{% endraw %} {% endraw %}
``` ```
@@ -19,7 +19,7 @@ Escapes a string without changing existing escaped entities. It doesn't change s
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "1 &lt; 2 &amp; 3" | escape_once }} {{ "1 &lt; 2 &amp; 3" | escape_once }}
{% endraw %} {% endraw %}
``` ```
+3 -3
View File
@@ -7,7 +7,7 @@ Returns the first item of an array.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | split: " " | first }} {{ "Ground control to Major Tom." | split: " " | first }}
{% endraw %} {% endraw %}
``` ```
@@ -19,7 +19,7 @@ Returns the first item of an array.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} {% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.first }} {{ 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: You can use `first` with dot notation when you need to use the filter inside a tag:
```liquid ```liquid
{% raw %} {%- raw -%}
{% if my_array.first == "zebra" %} {% if my_array.first == "zebra" %}
Here comes a zebra! Here comes a zebra!
{% endif %} {% endif %}
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 1.2 | floor }} {{ 1.2 | floor }}
{{ 2.0 | floor }} {{ 2.0 | floor }}
{{ 183.357 | floor }} {{ 183.357 | floor }}
@@ -25,7 +25,7 @@ Here the input value is a string:
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "3.5" | floor }} {{ "3.5" | floor }}
{% endraw %} {% endraw %}
``` ```
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} {% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | join: " and " }} {{ beatles | join: " and " }}
+3 -3
View File
@@ -7,7 +7,7 @@ Returns the last item of an array.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | split: " " | last }} {{ "Ground control to Major Tom." | split: " " | last }}
{% endraw %} {% endraw %}
``` ```
@@ -19,7 +19,7 @@ Returns the last item of an array.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} {% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.last }} {{ 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: You can use `last` with dot notation when you need to use the filter inside a tag:
```liquid ```liquid
{% raw %} {%- raw -%}
{% if my_array.last == "tiger" %} {% if my_array.last == "tiger" %}
There goes a tiger! There goes a tiger!
{% endif %} {% endif %}
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ " So much room for activities " | lstrip }}! {{ " So much room for activities " | lstrip }}!
{% endraw %} {% endraw %}
``` ```
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign all_categories = site.pages | map: "category" %} {% assign all_categories = site.pages | map: "category" %}
{% for item in all_categories %} {% for item in all_categories %}
+1 -1
View File
@@ -7,7 +7,7 @@ Subtracts a number from another number.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 4 | minus: 2 }} {{ 4 | minus: 2 }}
{{ 16 | minus: 4 }} {{ 16 | minus: 4 }}
{{ 183.357 | minus: 12 }} {{ 183.357 | minus: 12 }}
+1 -1
View File
@@ -7,7 +7,7 @@ Returns the remainder of a division operation.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 3 | modulo: 2 }} {{ 3 | modulo: 2 }}
{{ 24 | modulo: 7 }} {{ 24 | modulo: 7 }}
{{ 183.357 | modulo: 12 }} {{ 183.357 | modulo: 12 }}
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% capture string_with_newlines %} {% capture string_with_newlines %}
Hello Hello
there there
+1 -1
View File
@@ -7,7 +7,7 @@ Adds a number to another number.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 4 | plus: 2 }} {{ 4 | plus: 2 }}
{{ 16 | plus: 4 }} {{ 16 | plus: 4 }}
{{ 183.357 | plus: 12 }} {{ 183.357 | plus: 12 }}
+2 -2
View File
@@ -7,7 +7,7 @@ Adds the specified string to the beginning of another string.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }} {{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
{% endraw %} {% endraw %}
``` ```
@@ -21,7 +21,7 @@ Adds the specified string to the beginning of another string.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign url = "example.com" %} {% assign url = "example.com" %}
{{ "/index.html" | prepend: url }} {{ "/index.html" | prepend: url }}
{% endraw %} {% endraw %}
+1 -1
View File
@@ -7,7 +7,7 @@ Removes every occurrence of the specified substring from a string.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "I strained to see the train through the rain" | remove: "rain" }} {{ "I strained to see the train through the rain" | remove: "rain" }}
{% endraw %} {% endraw %}
``` ```
+1 -1
View File
@@ -7,7 +7,7 @@ Removes only the first occurrence of the specified substring from a string.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "I strained to see the train through the rain" | remove_first: "rain" }} {{ "I strained to see the train through the rain" | remove_first: "rain" }}
{% endraw %} {% endraw %}
``` ```
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }} {{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
{% endraw %} {% endraw %}
``` ```
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }} {{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
{% endraw %} {% endraw %}
``` ```
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | reverse | join: ", " }} {{ 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }} {{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
{% endraw %} {% endraw %}
``` ```
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 1.2 | round }} {{ 1.2 | round }}
{{ 2.7 | round }} {{ 2.7 | round }}
{{ 183.357 | round: 2 }} {{ 183.357 | round: 2 }}
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ " So much room for activities " | rstrip }}! {{ " So much room for activities " | rstrip }}!
{% endraw %} {% endraw %}
``` ```
+3 -3
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | size }} {{ "Ground control to Major Tom." | size }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.size }} {{ 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: You can use `size` with dot notation when you need to use the filter inside a tag:
```liquid ```liquid
{% raw %} {%- raw -%}
{% if site.pages.size > 10 %} {% if site.pages.size > 10 %}
This is a big website! This is a big website!
{% endif %} {% endif %}
+5 -5
View File
@@ -9,7 +9,7 @@ String or array indices are numbered starting from 0.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Liquid" | slice: 0 }} {{ "Liquid" | slice: 0 }}
{% endraw %} {% endraw %}
``` ```
@@ -21,7 +21,7 @@ String or array indices are numbered starting from 0.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Liquid" | slice: 2 }} {{ "Liquid" | slice: 2 }}
{% endraw %} {% endraw %}
``` ```
@@ -33,7 +33,7 @@ String or array indices are numbered starting from 0.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Liquid" | slice: 2, 5 }} {{ "Liquid" | slice: 2, 5 }}
{% endraw %} {% endraw %}
``` ```
@@ -47,7 +47,7 @@ Here the input value is an array:
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} {% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | slice: 1, 2 }} {{ beatles | slice: 1, 2 }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Liquid" | slice: -3, 2 }} {{ "Liquid" | slice: -3, 2 }}
{% endraw %} {% endraw %}
``` ```
+2 -2
View File
@@ -7,7 +7,7 @@ Sorts items in an array in case-sensitive order.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} {% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort | join: ", " }} {{ 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. An optional argument specifies which property of the array's items to use for sorting.
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign products_by_price = collection.products | sort: "price" %} {% assign products_by_price = collection.products | sort: "price" %}
{% for product in products_by_price %} {% for product in products_by_price %}
<h4>{{ product.title }}</h4> <h4>{{ product.title }}</h4>
+2 -2
View File
@@ -8,7 +8,7 @@ Sorts items in an array in case-insensitive order.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} {% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort_natural | join: ", " }} {{ 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. An optional argument specifies which property of the array's items to use for sorting.
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign products_by_company = collection.products | sort_natural: "company" %} {% assign products_by_company = collection.products | sort_natural: "company" %}
{% for product in products_by_company %} {% for product in products_by_company %}
<h4>{{ product.title }}</h4> <h4>{{ product.title }}</h4>
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} {% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{% for member in beatles %} {% for member in beatles %}
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ " So much room for activities " | strip }}! {{ " So much room for activities " | strip }}!
{% endraw %} {% endraw %}
``` ```
+1 -1
View File
@@ -7,7 +7,7 @@ Removes any HTML tags from a string.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }} {{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
{% endraw %} {% endraw %}
``` ```
+1 -1
View File
@@ -7,7 +7,7 @@ Removes any newline characters (line breaks) from a string.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% capture string_with_newlines %} {% capture string_with_newlines %}
Hello Hello
there there
+1 -1
View File
@@ -7,7 +7,7 @@ Multiplies a number by another number.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ 3 | times: 2 }} {{ 3 | times: 2 }}
{{ 24 | times: 7 }} {{ 24 | times: 7 }}
{{ 183.357 | times: 12 }} {{ 183.357 | times: 12 }}
+3 -3
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | truncate: 20 }} {{ "Ground control to Major Tom." | truncate: 20 }}
{% endraw %} {% endraw %}
``` ```
@@ -25,7 +25,7 @@ The length of the second argument counts against the number of characters specif
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }} {{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | truncate: 20, "" }} {{ "Ground control to Major Tom." | truncate: 20, "" }}
{% endraw %} {% endraw %}
``` ```
+3 -3
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | truncatewords: 3 }} {{ "Ground control to Major Tom." | truncatewords: 3 }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }} {{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Ground control to Major Tom." | truncatewords: 3, "" }} {{ "Ground control to Major Tom." | truncatewords: 3, "" }}
{% endraw %} {% endraw %}
``` ```
+1 -1
View File
@@ -7,7 +7,7 @@ Removes any duplicate items in an array.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %} {% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
{{ my_array | uniq | join: ", " }} {{ my_array | uniq | join: ", " }}
+2 -2
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Parker Moore" | upcase }} {{ "Parker Moore" | upcase }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "APPLE" | upcase }} {{ "APPLE" | upcase }}
{% endraw %} {% endraw %}
``` ```
+1 -1
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "%27Stop%21%27+said+Fred" | url_decode }} {{ "%27Stop%21%27+said+Fred" | url_decode }}
{% endraw %} {% endraw %}
``` ```
+2 -2
View File
@@ -7,7 +7,7 @@ Converts any URL-unsafe characters in a string into percent-encoded characters.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "john@liquid.com" | url_encode }} {{ "john@liquid.com" | url_encode }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{{ "Tetsuro Takara" | url_encode }} {{ "Tetsuro Takara" | url_encode }}
{% endraw %} {% endraw %}
``` ```
+3 -3
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
All products: All products:
{% for product in products %} {% for product in products %}
- {{ product.title }} - {{ 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
All products: All products:
{% for product in products %} {% for product in products %}
- {{ product.title }} - {{ 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign new_shirt = products | where: "type", "shirt" | first %} {% assign new_shirt = products | where: "type", "shirt" | first %}
Featured product: {{ new_shirt.title }} Featured product: {{ new_shirt.title }}
+5 -5
View File
@@ -12,7 +12,7 @@ Executes a block of code only if a certain condition is `true`.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% if product.title == "Awesome Shoes" %} {% if product.title == "Awesome Shoes" %}
These shoes are awesome! These shoes are awesome!
{% endif %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% unless product.title == "Awesome Shoes" %} {% unless product.title == "Awesome Shoes" %}
These shoes are not awesome. These shoes are not awesome.
{% endunless %} {% endunless %}
@@ -45,7 +45,7 @@ These shoes are not awesome.
This would be the equivalent of doing the following: This would be the equivalent of doing the following:
```liquid ```liquid
{% raw %} {%- raw -%}
{% if product.title != "Awesome Shoes" %} {% if product.title != "Awesome Shoes" %}
These shoes are not awesome. These shoes are not awesome.
{% endif %} {% endif %}
@@ -58,7 +58,7 @@ Adds more conditions within an `if` or `unless` block.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
<!-- If customer.name = "anonymous" --> <!-- If customer.name = "anonymous" -->
{% if customer.name == "kevin" %} {% if customer.name == "kevin" %}
Hey 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign handle = "cake" %} {% assign handle = "cake" %}
{% case handle %} {% case handle %}
{% when "cake" %} {% when "cake" %}
+16 -16
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% for product in collection.products %} {% for product in collection.products %}
{{ product.title }} {{ product.title }}
{% endfor %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% for product in collection.products %} {% for product in collection.products %}
{{ product.title }} {{ product.title }}
{% else %} {% else %}
@@ -49,7 +49,7 @@ Causes the loop to stop iterating when it encounters the `break` tag.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% for i in (1..5) %} {% for i in (1..5) %}
{% if i == 4 %} {% if i == 4 %}
{% break %} {% break %}
@@ -71,7 +71,7 @@ Causes the loop to skip the current iteration when it encounters the `continue`
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% for i in (1..5) %} {% for i in (1..5) %}
{% if i == 4 %} {% if i == 4 %}
{% continue %} {% continue %}
@@ -95,7 +95,7 @@ Limits the loop to the specified number of iterations.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
<!-- if array = [1,2,3,4,5,6] --> <!-- if array = [1,2,3,4,5,6] -->
{% for item in array limit:2 %} {% for item in array limit:2 %}
{{ item }} {{ item }}
@@ -114,7 +114,7 @@ Begins the loop at the specified index.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
<!-- if array = [1,2,3,4,5,6] --> <!-- if array = [1,2,3,4,5,6] -->
{% for item in array offset:2 %} {% for item in array offset:2 %}
{{ item }} {{ 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
<!-- if array = [1,2,3,4,5,6] --> <!-- if array = [1,2,3,4,5,6] -->
{% for item in array limit: 3 %} {% for item in array limit: 3 %}
{{ item }} {{ 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% for i in (3..5) %} {% for i in (3..5) %}
{{ i }} {{ i }}
{% endfor %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
<!-- if array = [1,2,3,4,5,6] --> <!-- if array = [1,2,3,4,5,6] -->
{% for item in array reversed %} {% for item in array reversed %}
{{ item }} {{ 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% cycle "one", "two", "three" %} {% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% cycle "first": "one", "two", "three" %} {% cycle "first": "one", "two", "three" %}
{% cycle "second": "one", "two", "three" %} {% cycle "second": "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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
<table> <table>
{% tablerow product in collection.products %} {% tablerow product in collection.products %}
{{ product.title }} {{ product.title }}
@@ -292,7 +292,7 @@ Defines how many columns the tables should have.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% tablerow product in collection.products cols:2 %} {% tablerow product in collection.products cols:2 %}
{{ product.title }} {{ product.title }}
{% endtablerow %} {% endtablerow %}
@@ -334,7 +334,7 @@ Defines how many columns the tables should have.
Exits the `tablerow` loop after a specific index. Exits the `tablerow` loop after a specific index.
```liquid ```liquid
{% raw %} {%- raw -%}
{% tablerow product in collection.products cols:2 limit:3 %} {% tablerow product in collection.products cols:2 limit:3 %}
{{ product.title }} {{ product.title }}
{% endtablerow %} {% endtablerow %}
@@ -346,7 +346,7 @@ Exits the `tablerow` loop after a specific index.
Starts the `tablerow` loop after a specific index. Starts the `tablerow` loop after a specific index.
```liquid ```liquid
{% raw %} {%- raw -%}
{% tablerow product in collection.products cols:2 offset:3 %} {% tablerow product in collection.products cols:2 offset:3 %}
{{ product.title }} {{ product.title }}
{% endtablerow %} {% 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. Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.
```liquid ```liquid
{% raw %} {%- raw -%}
<!--variable number example--> <!--variable number example-->
{% assign num = 4 %} {% assign num = 4 %}
+9 -9
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign verb = "turned" %} {% assign verb = "turned" %}
{% comment %} {% comment %}
{% assign verb = "converted" %} {% 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. Encloses multiple tags within one set of delimiters, to allow writing Liquid logic more concisely.
```liquid ```liquid
{% raw %} {%- raw -%}
{% liquid {% liquid
case section.blocks.size case section.blocks.size
when 1 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% liquid {% liquid
for product in collection.products for product in collection.products
echo product.title | capitalize echo product.title | capitalize
@@ -98,7 +98,7 @@ Hat Shirt Pants
Insert the rendered content of another template within the current template. Insert the rendered content of another template within the current template.
```liquid ```liquid
{% raw %} {%- raw -%}
{% render "template-name" %} {% render "template-name" %}
{% endraw %} {% 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. 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 ```liquid
{% raw %} {%- raw -%}
{% assign my_variable = "apples" %} {% assign my_variable = "apples" %}
{% render "name", my_variable: my_variable, my_other_variable: "oranges" %} {% render "name", my_variable: my_variable, my_other_variable: "oranges" %}
{% endraw %} {% 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. One or more objects can be passed to a template.
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign featured_product = all_products["product_handle"] %} {% assign featured_product = all_products["product_handle"] %}
{% render "product", product: featured_product %} {% render "product", product: featured_product %}
{% endraw %} {% 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. A single object can be passed to a template by using the `with` and optional `as` parameters.
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign featured_product = all_products["product_handle"] %} {% assign featured_product = all_products["product_handle"] %}
{% render "product" with featured_product as product %} {% render "product" with featured_product as product %}
{% endraw %} {% 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. A template can be rendered once for each value of an enumerable object by using the `for` and optional `as` parameters.
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign variants = product.variants %} {% assign variants = product.variants %}
{% render "product_variant" for variants as variant %} {% render "product_variant" for variants as variant %}
{% endraw %} {% 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. Insert the rendered content of another template within the current template.
```liquid ```liquid
{% raw %} {%- raw -%}
{% include "template-name" %} {% include "template-name" %}
{% endraw %} {% endraw %}
``` ```
+7 -7
View File
@@ -11,7 +11,7 @@ Creates a new named variable.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign my_variable = false %} {% assign my_variable = false %}
{% if my_variable != true %} {% if my_variable != true %}
This statement is valid. 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign foo = "bar" %} {% assign foo = "bar" %}
{{ foo }} {{ foo }}
{% endraw %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% capture my_variable %}I am being captured.{% endcapture %} {% capture my_variable %}I am being captured.{% endcapture %}
{{ my_variable }} {{ my_variable }}
{% endraw %} {% endraw %}
@@ -61,7 +61,7 @@ Using `capture`, you can create complex strings using other variables created wi
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign favorite_food = "pizza" %} {% assign favorite_food = "pizza" %}
{% assign age = 35 %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% increment my_counter %} {% increment my_counter %}
{% increment my_counter %} {% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% assign var = 10 %} {% assign var = 10 %}
{% increment var %} {% increment var %}
{% 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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {%- raw -%}
{% decrement variable %} {% decrement variable %}
{% decrement variable %} {% decrement variable %}
{% decrement variable %} {% decrement variable %}