From 57d41e535f7eb6f4c8c4c152d4b1152eeb0de904 Mon Sep 17 00:00:00 2001 From: Shaina Raskas Date: Tue, 18 Oct 2022 15:38:24 -0400 Subject: [PATCH 1/6] draft --- _basics/variations.md | 4 +- _tags/control-flow.md | 2 + _tags/iteration.md | 184 +++++++++++++++++++++++++++++++++++++++++- _tags/template.md | 2 +- 4 files changed, 187 insertions(+), 5 deletions(-) diff --git a/_basics/variations.md b/_basics/variations.md index ad311306..7cddecf0 100644 --- a/_basics/variations.md +++ b/_basics/variations.md @@ -3,7 +3,7 @@ title: Variations of Liquid description: An overview of the different installations of Liquid and how Liquid can change depending on where you're using it. --- -Liquid is a flexible, safe language, and is used in many different environments. Liquid was created for use in [Shopify](https://www.shopify.com) stores, and is also used extensively on [Jekyll](https://jekyllrb.com) websites. Over time, both Shopify and Jekyll have added their own objects, tags, and filters to Liquid. The most popular versions of Liquid that exist are **Liquid**, **Shopify Liquid**, and **Jekyll Liquid**. +Liquid is a flexible, safe language, and is used in many different environments. Liquid was created for use in [Shopify](https://www.shopify.com) stores, and is also used extensively on [Jekyll](https://jekyllrb.com) websites. Over time, both Shopify and Jekyll have added their own objects, tags, and filters to Liquid. The most popular versions of Liquid that exist are **Liquid**, **Shopify Liquid for themes**, and **Jekyll Liquid**. This site documents the latest version of **Liquid** including betas and release candidates — that is, Liquid as it exists outside of Shopify and Jekyll. If you download the Liquid repository or install it as a [gem](https://rubygems.org/gems/liquid), you will get access to whatever objects, tags, and filters are in the version of Liquid that you chose. @@ -11,7 +11,7 @@ This site documents the latest version of **Liquid** including betas and release Shopify always uses the latest version of Liquid as a base, but Shopify adds a significant number of objects, tags, and filters to Liquid for use in merchants' stores. These include objects representing store, product, and customer information, and filters for displaying store data and manipulating storefront assets like product images. -Shopify's version of Liquid is documented in the [Shopify developer documentation](https://shopify.dev/docs/themes/liquid/reference). If you want to try out Shopify's version of Liquid, you can create a development store through the [Shopify Partner Dashboard](https://help.shopify.com/en/partners/dashboard/managing-stores/development-stores). +Shopify has several versions of Liquid. The most popular version is used to build Shopify themes. To learn about the Liquid elements that you can use to build Shopify themes, and to learn about the other versions of Liquid at Shopify, refer to the [Shopify Liquid reference](https://shopify.dev/api/liquid). ## Jekyll diff --git a/_tags/control-flow.md b/_tags/control-flow.md index 457f560b..f2e7d725 100644 --- a/_tags/control-flow.md +++ b/_tags/control-flow.md @@ -79,6 +79,8 @@ Hey Anonymous! Creates a switch statement to execute a particular block of code when a variable has a specified value. `case` initializes the switch statement, and `when` statements define the various conditions. +A `when` tag can accept multiple values. When multiple values are provided, the expression is returned when the variable matches any of the values inside of the tag. Provide the values as a comma-separated list, or separate them using an `or` operator. + An optional `else` statement at the end of the case provides code to execute if none of the conditions are met.

Input

diff --git a/_tags/iteration.md b/_tags/iteration.md index 2d68031e..731fc9af 100644 --- a/_tags/iteration.md +++ b/_tags/iteration.md @@ -7,7 +7,7 @@ Iteration tags repeatedly run blocks of code. ## for -Repeatedly executes a block of code. For a full list of attributes available within a `for` loop, see [forloop (object)](https://shopify.dev/docs/themes/liquid/reference/objects/for-loops). +Repeatedly executes a block of code. For a full list of attributes available within a `for` loop, refer to [forloop (object)](#forloop-object).

Input

```liquid @@ -192,6 +192,91 @@ Reverses the order of the loop. Note that this flag's spelling is different from 6 5 4 3 2 1 ``` +## forloop (object) + +Information about a parent [`for` loop](#for). + +```json +{ + "first": true, + "index": 1, + "index0": 0, + "last": false, + "length": 4, + "rindex": 3 +} +``` + +### Use the `forloop` object + +

Input

+```liquid +{%- raw -%} +{% assign smoothie_flavors = "orange, strawberry, banana" | split: ", " %} + +{% for flavor in smoothie_flavors -%} + {%- if forloop.length > 0 -%} + {{ flavor }}{% unless forloop.last %}-{% endunless -%} + {%- endif -%} +{% endfor %} +{% endraw %} +``` + +

Input

+```text +orange-strawberry-banana +``` + +### properties + +#### length + +The total number of iterations in the loop. + +returns `number` + +#### parentloop + +The parent `forloop` object. If the current `for` loop isn't nested inside another `for` loop, then `nil` is returned. + +returns `forloop` + +#### index + +The 1-based index of the current iteration. + +returns `number` + +#### index0 + +The 0-based index of the current iteration. + +returns `number` + +#### rindex + +The 1-based index of the current iteration, in reverse order. + +returns `number` + +#### rindex0 + +The 0-based index of the current iteration, in reverse order. + +returns `number` + +#### first + +Returns `true` if the current iteration is the first. Returns `false` if not. + +returns `boolean` + +#### last + +Returns `true` if the current iteration is the last. Returns `false` if not. + +returns `boolean` + ## cycle 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. @@ -245,7 +330,7 @@ Uses for `cycle` include: ## tablerow -Generates an HTML table. Must be wrapped in opening `` and closing `
` HTML tags. For a full list of attributes available within a `tablerow` loop, see [tablerow (object)](https://shopify.dev/docs/themes/liquid/reference/objects/tablerow). +Generates an HTML table. Must be wrapped in opening `` and closing `
` HTML tags. For a full list of attributes available within a `tablerow` loop, see [tablerowloop (object)](#tablerowloop-object).

Input

```liquid @@ -377,3 +462,98 @@ Defines a range of numbers to loop through. The range can be defined by both lit {% endraw %} ``` + +## tablerowloop (object) + +Information about a parent [`tablerow` loop](#tablerow). + +```json +{ + "col": 1, + "col0": 0, + "col_first": true, + "col_last": false, + "first": true, + "index": 1, + "index0": 0, + "last": false, + "length": 5, + "rindex": 5, + "rindex0": 4, + "row": 1 +} +``` + +### Properties + +#### col + +The 1-based index of the current column. + +returns `number` + +#### col0 + +The 0-based index of the current column. + +returns `number` + +#### col_first + +Returns `true` if the current column is the first in the row. Returns `false` if not. + +returns `boolean` + +#### col_last + +Returns `true` if the current column is the last in the row. Returns `false` if not. + +returns `boolean` + +#### first + +Returns `true` if the current iteration is the first. Returns `false` if not. + +returns `boolean` + +#### index + +The 1-based index of the current iteration. + +returns `number` + +#### index0 + +The 0-based index of the current iteration. + +returns `number` + +#### last + +Returns `true` if the current iteration is the last. Returns `false` if not. + +returns `boolean` + +#### length + +The total number of iterations in the loop. + +returns `number` + +#### rindex + +The 1-based index of the current iteration, in reverse order. + +returns `number` + +#### rindex0 + +The 0-based index of the current iteration, in reverse order. + +returns `number` + +#### row + +The 1-based index of current row. + +returns `number` \ No newline at end of file diff --git a/_tags/template.md b/_tags/template.md index 21420354..08d829e7 100644 --- a/_tags/template.md +++ b/_tags/template.md @@ -153,7 +153,7 @@ A template can be rendered once for each value of an enumerable object by using In the example above, the template will be rendered once for each variant of the product, and the `variant` variable will hold a different product variant object for each iteration. -When using the `for` parameter, the [`forloop`](https://shopify.dev/docs/themes/liquid/reference/objects/for-loops) object is accessible within the rendered template. +When using the `for` parameter, the [`forloop`](({{ "/tags/iteration/#forloop-object" | prepend: site.baseurl }})) object is accessible within the rendered template. ## include From 2f8dc74f95be9cb0551045315744ee5ef0e13dd8 Mon Sep 17 00:00:00 2001 From: Shaina Raskas Date: Tue, 18 Oct 2022 16:01:41 -0400 Subject: [PATCH 2/6] use tables instead of headings --- _tags/iteration.md | 146 ++++++++------------------------------------- 1 file changed, 25 insertions(+), 121 deletions(-) diff --git a/_tags/iteration.md b/_tags/iteration.md index 731fc9af..a25fbf4c 100644 --- a/_tags/iteration.md +++ b/_tags/iteration.md @@ -222,60 +222,22 @@ Information about a parent [`for` loop](#for). {% endraw %} ``` -

Input

+

Output

```text orange-strawberry-banana ``` -### properties +### forloop (properties) -#### length - -The total number of iterations in the loop. - -returns `number` - -#### parentloop - -The parent `forloop` object. If the current `for` loop isn't nested inside another `for` loop, then `nil` is returned. - -returns `forloop` - -#### index - -The 1-based index of the current iteration. - -returns `number` - -#### index0 - -The 0-based index of the current iteration. - -returns `number` - -#### rindex - -The 1-based index of the current iteration, in reverse order. - -returns `number` - -#### rindex0 - -The 0-based index of the current iteration, in reverse order. - -returns `number` - -#### first - -Returns `true` if the current iteration is the first. Returns `false` if not. - -returns `boolean` - -#### last - -Returns `true` if the current iteration is the last. Returns `false` if not. - -returns `boolean` +| Property | Description | Returns | +| `length` | The total number of iterations in the loop. | `number` | +| `parentloop` | The parent `forloop` object. If the current `for` loop isn't nested inside another `for` loop, then `nil` is returned. | `forloop` | +| `index` | The 1-based index of the current iteration. | `number` | +| `index0` | The 0-based index of the current iteration. | `number` | +| `rindex` | The 1-based index of the current iteration, in reverse order. | `number` | +| `rindex0` | The 0-based index of the current iteration, in reverse order. | `number` | +| `first` | Returns `true` if the current iteration is the first. Returns `false` if not. | `boolean` | +| `last` | Returns `true` if the current iteration is the last. Returns `false` if not. | `boolean` | ## cycle @@ -484,76 +446,18 @@ Information about a parent [`tablerow` loop](#tablerow). } ``` -### Properties +### tablerowloop (properties) -#### col - -The 1-based index of the current column. - -returns `number` - -#### col0 - -The 0-based index of the current column. - -returns `number` - -#### col_first - -Returns `true` if the current column is the first in the row. Returns `false` if not. - -returns `boolean` - -#### col_last - -Returns `true` if the current column is the last in the row. Returns `false` if not. - -returns `boolean` - -#### first - -Returns `true` if the current iteration is the first. Returns `false` if not. - -returns `boolean` - -#### index - -The 1-based index of the current iteration. - -returns `number` - -#### index0 - -The 0-based index of the current iteration. - -returns `number` - -#### last - -Returns `true` if the current iteration is the last. Returns `false` if not. - -returns `boolean` - -#### length - -The total number of iterations in the loop. - -returns `number` - -#### rindex - -The 1-based index of the current iteration, in reverse order. - -returns `number` - -#### rindex0 - -The 0-based index of the current iteration, in reverse order. - -returns `number` - -#### row - -The 1-based index of current row. - -returns `number` \ No newline at end of file +| Property | Description | Returns | +| `col` | The 1-based index of the current column. | `number` | +| `col0` | The 0-based index of the current column. | `number` | +| `col_first` | Returns `true` if the current column is the first in the row. Returns `false` if not. | `boolean` | +| `col_last` | Returns `true` if the current column is the last in the row. Returns `false` if not. | `boolean` | +| `first` | Returns `true` if the current iteration is the first. Returns `false` if not. | `boolean` | +| `index` | The 1-based index of the current iteration. | `number` | +| `index0` | The 0-based index of the current iteration. | `number` | +| `last` | Returns `true` if the current iteration is the last. Returns `false` if not. | `boolean` | +| `length` | The total number of iterations in the loop. | `number` | +| `rindex` | The 1-based index of the current iteration, in reverse order. | `number` | +| `rindex0` | The 0-based index of the current iteration, in reverse order. | `number` | +| `row` | The 1-based index of current row. | `number` | From 99a59e39d81a9b1598aa570351ed88b0f2b251f4 Mon Sep 17 00:00:00 2001 From: Shaina Raskas Date: Tue, 18 Oct 2022 16:04:14 -0400 Subject: [PATCH 3/6] fix link formatting --- _tags/template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_tags/template.md b/_tags/template.md index 08d829e7..0db116cd 100644 --- a/_tags/template.md +++ b/_tags/template.md @@ -153,7 +153,7 @@ A template can be rendered once for each value of an enumerable object by using In the example above, the template will be rendered once for each variant of the product, and the `variant` variable will hold a different product variant object for each iteration. -When using the `for` parameter, the [`forloop`](({{ "/tags/iteration/#forloop-object" | prepend: site.baseurl }})) object is accessible within the rendered template. +When using the `for` parameter, the [`forloop`]({{ "/tags/iteration/#forloop-object" | prepend: site.baseurl }}) object is accessible within the rendered template. ## include From c52e75a9b551fd8d5cd0364108e27cc638741c4d Mon Sep 17 00:00:00 2001 From: Shaina Raskas Date: Tue, 18 Oct 2022 16:05:43 -0400 Subject: [PATCH 4/6] grammar and language --- _tags/iteration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_tags/iteration.md b/_tags/iteration.md index a25fbf4c..772dc6cc 100644 --- a/_tags/iteration.md +++ b/_tags/iteration.md @@ -292,7 +292,7 @@ Uses for `cycle` include: ## tablerow -Generates an HTML table. Must be wrapped in opening `` and closing `
` HTML tags. For a full list of attributes available within a `tablerow` loop, see [tablerowloop (object)](#tablerowloop-object). +Generates an HTML table. Must be wrapped in opening `` and closing `
` HTML tags. For a full list of attributes available within a `tablerow` loop, refer to [tablerowloop (object)](#tablerowloop-object).

Input

```liquid From 622b3b9a1da4fc919566d524b0d84a7d3b984388 Mon Sep 17 00:00:00 2001 From: Shaina Raskas Date: Wed, 19 Oct 2022 09:14:57 -0400 Subject: [PATCH 5/6] feedback --- _tags/iteration.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/_tags/iteration.md b/_tags/iteration.md index 772dc6cc..8cf65a4b 100644 --- a/_tags/iteration.md +++ b/_tags/iteration.md @@ -7,7 +7,7 @@ Iteration tags repeatedly run blocks of code. ## for -Repeatedly executes a block of code. For a full list of attributes available within a `for` loop, refer to [forloop (object)](#forloop-object). +Repeatedly executes a block of code. For a full list of attributes available within a `for` loop, refer to the [`forloop` object](#forloop-object).

Input

```liquid @@ -230,6 +230,7 @@ orange-strawberry-banana ### forloop (properties) | Property | Description | Returns | +| --- | --- | --- | | `length` | The total number of iterations in the loop. | `number` | | `parentloop` | The parent `forloop` object. If the current `for` loop isn't nested inside another `for` loop, then `nil` is returned. | `forloop` | | `index` | The 1-based index of the current iteration. | `number` | @@ -292,7 +293,7 @@ Uses for `cycle` include: ## tablerow -Generates an HTML table. Must be wrapped in opening `` and closing `
` HTML tags. For a full list of attributes available within a `tablerow` loop, refer to [tablerowloop (object)](#tablerowloop-object). +Generates an HTML table. Must be wrapped in opening `` and closing `
` HTML tags. For a full list of attributes available within a `tablerow` loop, refer to the [`tablerowloop` object](#tablerowloop-object).

Input

```liquid @@ -449,6 +450,7 @@ Information about a parent [`tablerow` loop](#tablerow). ### tablerowloop (properties) | Property | Description | Returns | +| --- | --- | --- | | `col` | The 1-based index of the current column. | `number` | | `col0` | The 0-based index of the current column. | `number` | | `col_first` | Returns `true` if the current column is the first in the row. Returns `false` if not. | `boolean` | From 8e5911d3ee0a500c9e4cfe3748b18dd8bff8228c Mon Sep 17 00:00:00 2001 From: Shaina Raskas Date: Wed, 19 Oct 2022 10:43:53 -0400 Subject: [PATCH 6/6] document inline comments --- _tags/template.md | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/_tags/template.md b/_tags/template.md index 0db116cd..b0b542e6 100644 --- a/_tags/template.md +++ b/_tags/template.md @@ -34,6 +34,54 @@ Anything you put between {% comment %} and {% endcomment %} tags is {{ verb }} into a comment. ``` +## Inline comments {%- include version-badge.html version="5.4.0" %} + +You can use inline comments to prevent an expression from being rendered or output. Any text inside of the tag also won't be rendered or output. + +You can create multi-line inline comments. However, each line must begin with a `#`. + +

Input

+```liquid +{%- raw -%} +{% # for i in (1..3) -%} + {{ i }} +{% # endfor %} + +{% + ############################### + # This is a comment + # across multiple lines + ############################### +%} +{% endraw %} +``` + +

Output

+```text + + +``` + +### Inline comments inside `liquid` tags + +You can use the inline comment tag inside [`liquid` tags](#liquid). The tag must be used for each line that you want to comment. + +

Input

+```liquid +{%- raw -%} +{% liquid + # this is a comment + assign topic = 'Learning about comments!' + echo topic +%} +{% endraw %} +``` + +

Output

+```text +Learning about comments! +``` + ## raw Temporarily disables tag processing. This is useful for generating certain content that uses conflicting syntax, such as [Mustache](https://mustache.github.io/) or [Handlebars](https://handlebarsjs.com/).