mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-17 01:40:42 -07:00
Adjust whitespace
This commit is contained in:
@@ -10,7 +10,6 @@ Liquid code can be categorized into [**objects**](#objects), [**tags**](#tags),
|
||||
|
||||
**Objects** tell Liquid where to show content on a page. Objects and variable names are denoted by double curly braces: `{% raw %}{{{% endraw %}` and `{% raw %}}}{% endraw %}`.
|
||||
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
@@ -53,7 +52,6 @@ Tags can be categorized into three types:
|
||||
|
||||
You can read more about each type of tag in their respective sections.
|
||||
|
||||
|
||||
## Filters
|
||||
|
||||
**Filters** change the output of a Liquid object. They are used within an output and are separated by a `|`.
|
||||
|
||||
@@ -7,7 +7,6 @@ Removes any `nil` values from an array.
|
||||
|
||||
For this example, assume `site.pages` is an array of content pages for a website, and some of these pages have an attribute called `category` that specifies their content category. If we `map` those categories to an array, some of the array items might be `nil` if any pages do not have a `category` attribute.
|
||||
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
|
||||
@@ -23,7 +23,6 @@ You can also `prepend` variables:
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% assign url = "example.com" %}
|
||||
|
||||
{{ "/index.html" | prepend: url }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -31,6 +30,5 @@ You can also `prepend` variables:
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% assign url = "example.com" %}
|
||||
|
||||
{{ "/index.html" | prepend: url }}
|
||||
```
|
||||
|
||||
+4
-9
@@ -13,14 +13,14 @@ In this example, assume you have a list of products and you want to show your ki
|
||||
All products:
|
||||
{% for product in products %}
|
||||
- {{ product.title }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
{% assign kitchen_products = products | where: "type", "kitchen" %}
|
||||
|
||||
Kitchen products:
|
||||
{% for product in kitchen_products %}
|
||||
- {{ product.title }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
@@ -35,7 +35,6 @@ All products:
|
||||
Kitchen products:
|
||||
- Spatula
|
||||
- Garlic press
|
||||
|
||||
```
|
||||
|
||||
Say instead you have a list of products and you only want to show those that are available to buy. You can `where` with a property name but no target value to include all products with a [truthy]({{ "/basics/truthy-and-falsy#truthy" | prepend: site.baseurl }}) `"available"` value.
|
||||
@@ -44,22 +43,20 @@ Say instead you have a list of products and you only want to show those that are
|
||||
{% raw %}
|
||||
```liquid
|
||||
All products:
|
||||
{% for product in products %}
|
||||
{% for product in products %}
|
||||
- {{ product.title }}
|
||||
{% endfor %}
|
||||
|
||||
{% assign available_products = products | where: "available" %}
|
||||
|
||||
Available products:
|
||||
{% for product in available_products %}
|
||||
{% for product in available_products %}
|
||||
- {{ product.title }}
|
||||
{% endfor %}
|
||||
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
|
||||
```text
|
||||
All products:
|
||||
- Coffee mug
|
||||
@@ -69,10 +66,8 @@ All products:
|
||||
Available products:
|
||||
- Coffee mug
|
||||
- Boring sneakers
|
||||
|
||||
```
|
||||
|
||||
|
||||
The `where` filter can also be used to find a single object in an array when combined with the `first` filter. For example, say you want to show off the shirt in your new fall collection.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
|
||||
+5
-5
@@ -12,9 +12,9 @@ Repeatedly executes a block of code. For a full list of attributes available wit
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% for product in collection.products %}
|
||||
{{ product.title }}
|
||||
{% endfor %}
|
||||
{% for product in collection.products %}
|
||||
{{ product.title }}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -196,8 +196,8 @@ one
|
||||
|
||||
Uses for `cycle` include:
|
||||
|
||||
- applying odd/even classes to rows in a table
|
||||
- applying a unique class to the last product thumbnail in a row
|
||||
- applying odd/even classes to rows in a table
|
||||
- applying a unique class to the last product thumbnail in a row
|
||||
|
||||
## cycle (parameters)
|
||||
|
||||
|
||||
+2
-1
@@ -21,7 +21,7 @@ Creates a new variable.
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
This statement is valid.
|
||||
This statement is valid.
|
||||
```
|
||||
|
||||
Wrap a variable in quotations `"` to save it as a string.
|
||||
@@ -55,6 +55,7 @@ Captures the string inside of the opening and closing tags and assigns it to a v
|
||||
```text
|
||||
I am being captured.
|
||||
```
|
||||
|
||||
Using `capture`, you can create complex strings using other variables created with `assign`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
|
||||
Reference in New Issue
Block a user