mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Simpler code snippets + magic CSS
This commit is contained in:
+5
-3
@@ -4,18 +4,20 @@ description: "Liquid is a template language and accompanying rendering engine. I
|
|||||||
# Build settings
|
# Build settings
|
||||||
baseurl: "" # the subpath of your site, e.g. /blog/
|
baseurl: "" # the subpath of your site, e.g. /blog/
|
||||||
url: http://liquidmarkup.org # the base hostname & protocol for your site
|
url: http://liquidmarkup.org # the base hostname & protocol for your site
|
||||||
markdown: kramdown
|
markdown: redcarpet
|
||||||
|
redcarpet:
|
||||||
|
extensions: ["with_toc_data", "tables", "disable_indented_code_blocks", "no_intra_emphasis"]
|
||||||
highlighter: pygments
|
highlighter: pygments
|
||||||
permalink: pretty
|
permalink: pretty
|
||||||
exclude:
|
exclude:
|
||||||
- README.md
|
- README.md
|
||||||
- CNAME
|
- CNAME
|
||||||
- node_modules
|
- node_modules
|
||||||
keep_files: ['css']
|
keep_files: ["css"]
|
||||||
|
|
||||||
# Front matter defaults
|
# Front matter defaults
|
||||||
defaults:
|
defaults:
|
||||||
- scope:
|
- scope:
|
||||||
path: "" # an empty string here means all files in the project
|
path: "" # an empty string here means all files in the project
|
||||||
values:
|
values:
|
||||||
layout: "default"
|
layout: default
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
layout: default
|
||||||
|
---
|
||||||
|
|
||||||
|
{{ content }}
|
||||||
|
|
||||||
|
{% for item in page.examples %}
|
||||||
|
|
||||||
|
<code>{{ item }}</code>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
@@ -2,32 +2,29 @@
|
|||||||
margin-bottom: $spacing-unit * 2;
|
margin-bottom: $spacing-unit * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.code-block {
|
.highlight {
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
border-radius: 0 0 3px 3px;
|
|
||||||
border-top: none;
|
border-top: none;
|
||||||
|
border-radius: 0 0 3px 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:before {
|
&:before {
|
||||||
padding: 8px 12px;
|
content: "Example";
|
||||||
display: block;
|
display: block;
|
||||||
box-sizing: border-box;
|
padding: 8px 12px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: $color-white;
|
color: $color-white;
|
||||||
background: $color-blue-5;
|
background: $color-blue-5;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
border-radius: 3px 3px 0 0;
|
border-radius: 3px 3px 0 0;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.code-block--input {
|
& + .highlight {
|
||||||
&:before {
|
&:before {
|
||||||
content: 'Input';
|
content: "Output";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.code-block--output {
|
|
||||||
&:before {
|
|
||||||
content: 'Output';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-13
@@ -45,40 +45,44 @@ Liquid includes many logical and comparison operators.
|
|||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
<div>
|
```liquid
|
||||||
{% highlight liquid %}{% raw %}
|
{% raw %}
|
||||||
{% if product.title == "Awesome Shoes" %}
|
{% if product.title == "Awesome Shoes" %}
|
||||||
These shoes are awesome!
|
These shoes are awesome!
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
You can use multiple operators in a tag:
|
You can use multiple operators in a tag:
|
||||||
|
|
||||||
<div>
|
```liquid
|
||||||
{% highlight 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 %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
## contains
|
## contains
|
||||||
|
|
||||||
`contains` checks for the presence of a substring inside a string.
|
`contains` checks for the presence of a substring inside a string.
|
||||||
|
|
||||||
{% highlight liquid %}{% raw %}
|
```liquid
|
||||||
|
{% 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 %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
`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.
|
||||||
|
|
||||||
{% highlight liquid %}{% raw %}
|
```liquid
|
||||||
|
{% 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 %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
`contains` is can only search strings. You cannot use it to check for an object in an array of objects.
|
`contains` can only search strings. You cannot use it to check for an object in an array of objects.
|
||||||
|
|||||||
+16
-18
@@ -10,45 +10,43 @@ 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:
|
||||||
|
|
||||||
{% highlight liquid %}{% raw %}
|
```liquid
|
||||||
|
{% raw %}
|
||||||
{% assign tobi = 'Tobi' %}
|
{% assign tobi = 'Tobi' %}
|
||||||
|
|
||||||
{% if tobi == true %}
|
{% if tobi == true %}
|
||||||
This condition will always be true.
|
This condition will always be true.
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
[Strings](/basics/types/#string), even when empty, are truthy. The example below will result in empty HTML tags if `settings.fp_heading` is empty:
|
[Strings](/basics/types/#string), even when empty, are truthy. The example below will result in empty HTML tags if `settings.fp_heading` is empty:
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% raw %}
|
{% raw %}
|
||||||
{% if settings.fp_heading %}
|
{% if settings.fp_heading %}
|
||||||
<h1>{{ settings.fp_heading }}</h1>
|
<h1>{{ settings.fp_heading }}</h1>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```html
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<h1></h1>
|
<h1></h1>
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
[EmptyDrops](/basics/types/#emptydrop) are also truthy. In the example below, if `settings.page` is an empty string or set to a hidden or deleted object, you will end up with an EmptyDrop. The result is an empty div:
|
[EmptyDrops](/basics/types/#emptydrop) are also truthy. In the example below, if `settings.page` is an empty string or set to a hidden or deleted object, you will end up with an EmptyDrop. The result is an empty div:
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% raw %}
|
{% raw %}
|
||||||
{% if pages[settings.page] %}
|
{% if pages[settings.page] %}
|
||||||
<div>{{ pages[settings.page].content }}</div>
|
<div>{{ pages[settings.page].content }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```html
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<div></div>
|
<div></div>
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
## Falsy
|
## Falsy
|
||||||
|
|
||||||
|
|||||||
+44
-44
@@ -17,33 +17,33 @@ Liquid variables can be initialized by using the [assign](/tags/#assign) or [cap
|
|||||||
|
|
||||||
Strings are declared by wrapping a variable's value in single or double quotes.
|
Strings are declared by wrapping a variable's value in single or double quotes.
|
||||||
|
|
||||||
{% highlight liquid %}
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
{% assign my_string = "Hello World!" %}
|
{% assign my_string = "Hello World!" %}
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
{% endhighlight %}
|
```
|
||||||
|
|
||||||
## Number
|
## Number
|
||||||
|
|
||||||
Numbers include floats and integers.
|
Numbers include floats and integers.
|
||||||
|
|
||||||
{% highlight liquid %}
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
{% assign my_int = 25 %}
|
{% assign my_int = 25 %}
|
||||||
{% assign my_float = 39.756 %}
|
{% assign my_float = 39.756 %}
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
{% endhighlight %}
|
```
|
||||||
|
|
||||||
## Boolean
|
## Boolean
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
{% highlight liquid %}
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
{% assign foo = true %}
|
{% assign foo = true %}
|
||||||
{% assign bar = false %}
|
{% assign bar = false %}
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
{% endhighlight %}
|
```
|
||||||
|
|
||||||
## Nil
|
## Nil
|
||||||
|
|
||||||
@@ -53,27 +53,25 @@ Nil is treated as false in the conditions of `if` blocks and other Liquid tags t
|
|||||||
|
|
||||||
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:
|
||||||
|
|
||||||
{% highlight liquid %}
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
{% if user %}
|
{% if user %}
|
||||||
Hello {{ user.name }}!
|
Hello {{ user.name }}!
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
{% endhighlight %}
|
```
|
||||||
|
|
||||||
Tags or outputs that return `nil` will not print anything to the page.
|
Tags or outputs that return `nil` will not print anything to the page.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight liquid %}{% raw %}
|
{% raw %}
|
||||||
The current user is {{ user.name }}
|
The current user is {{ user.name }}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight text %}{% raw %}
|
|
||||||
The current user is
|
The current user is
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
## Array
|
## Array
|
||||||
|
|
||||||
@@ -83,41 +81,39 @@ Arrays hold lists of variables of any type.
|
|||||||
|
|
||||||
To access all of the items in an array, you can loop through each item in the array using a [for](/tags/#for) or [tablerow](/tags/#tablerow) tag.
|
To access all of the items in an array, you can loop through each item in the array using a [for](/tags/#for) or [tablerow](/tags/#tablerow) tag.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight liquid %}{% raw %}
|
{% raw %}
|
||||||
<!-- if site.users = "Tobi", "Lina", "Tetsuro", "Adam" -->
|
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
|
||||||
{% for user in site.users %}
|
{% for user in site.users %}
|
||||||
{{ user }}
|
{{ user }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight text %}{% raw %}
|
{% raw %}
|
||||||
Tobi Lina Tetsuro Adam
|
Tobi Laura Tetsuro Adam
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
### Accessing specific items in arrays
|
### Accessing specific items in arrays
|
||||||
|
|
||||||
You can use square bracket `[ ]` notation to access a specific item in an array. Array indexing starts at zero.
|
You can use square bracket `[` `]` notation to access a specific item in an array. Array indexing starts at zero.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight liquid %}{% raw %}
|
{% raw %}
|
||||||
<!-- if site.users = "Tobi", "Lina", "Tetsuro", "Adam" -->
|
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
|
||||||
{{ site.users[0] }}
|
{{ site.users[0] }}
|
||||||
{{ site.users[1] }}
|
{{ site.users[1] }}
|
||||||
{{ site.users[3] }}
|
{{ site.users[3] }}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight text %}{% raw %}
|
|
||||||
Tobi
|
Tobi
|
||||||
Lina
|
Laura
|
||||||
Adam
|
Adam
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
### Initializing arrays
|
### Initializing arrays
|
||||||
|
|
||||||
@@ -129,12 +125,14 @@ You can, however, use the [split](/filters/#split) filter to break a single stri
|
|||||||
|
|
||||||
An EmptyDrop object is returned if you try to access a deleted object (such as a page or post) by its [handle](/basics/#Handles). 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 (such as a page or post) by its [handle](/basics/#Handles). In the example below, `page_1`, `page_2` and `page_3` are all EmptyDrop objects.
|
||||||
|
|
||||||
{% highlight liquid %}{% raw %}
|
```liquid
|
||||||
|
{% 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"] %}
|
||||||
{% assign page_3 = pages.this-handle-does-not-exist %}
|
{% assign page_3 = pages.this-handle-does-not-exist %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
EmptyDrop objects only have one attribute, `empty?`, which is always *true*.
|
EmptyDrop objects only have one attribute, `empty?`, which is always *true*.
|
||||||
|
|
||||||
@@ -144,17 +142,19 @@ Collections and pages that *do* exist do not have an `empty?` attribute. Their `
|
|||||||
|
|
||||||
Using the `empty?` attribute, you can check to see if an object exists or not before you access any of its attributes.
|
Using the `empty?` attribute, you can check to see if an object exists or not before you access any of its attributes.
|
||||||
|
|
||||||
{% highlight liquid %}{% raw %}
|
```liquid
|
||||||
|
{% raw %}
|
||||||
{% unless pages.about.empty? %}
|
{% unless pages.about.empty? %}
|
||||||
<!-- This content will only print if the page with handle 'about' is not empty -->
|
<!-- This will only print if the page with handle 'about' is not empty -->
|
||||||
<h1>{{ pages.frontpage.title }}</h1>
|
<h1>{{ pages.frontpage.title }}</h1>
|
||||||
<div>{{ pages.frontpage.content }}</div>
|
<div>{{ pages.frontpage.content }}</div>
|
||||||
{% endunless %}
|
{% endunless %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
If you don't check for emptiness first, Liquid may print empty HTML elements to the page:
|
If you don't check for emptiness first, Liquid may print empty HTML elements to the page:
|
||||||
|
|
||||||
{% highlight html %}{% raw %}
|
```html
|
||||||
<h1></h1>
|
<h1></h1>
|
||||||
<div></div>
|
<div></div>
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
|
|||||||
+15
-7
@@ -4,19 +4,27 @@ title: append
|
|||||||
|
|
||||||
`append` concatenates two strings and returns the concatenated value.
|
`append` concatenates two strings and returns the concatenated value.
|
||||||
|
|
||||||
{% highlight liquid %}
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
{{ "/my/fancy/url" | append:".html" }}
|
{{ "/my/fancy/url" | append:".html" }}
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
# => "/my/fancy/url.html"
|
```
|
||||||
{% endhighlight %}
|
|
||||||
|
|
||||||
It can also be used with variables:
|
```text
|
||||||
|
/my/fancy/url.html
|
||||||
|
```
|
||||||
|
|
||||||
{% highlight liquid %}
|
`append` can also be used with variables:
|
||||||
|
|
||||||
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
{% assign filename = "/index.html" %}
|
{% assign filename = "/index.html" %}
|
||||||
{{ product.url | append: filename }}
|
{{ product.url | append: filename }}
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
# => "#{product.url}/index.html"
|
```
|
||||||
{% endhighlight %}
|
|
||||||
|
```liquid
|
||||||
|
{% raw %}
|
||||||
|
{{ product.url }}/index.html
|
||||||
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|||||||
+20
-5
@@ -4,9 +4,24 @@ title: capitalize
|
|||||||
|
|
||||||
`capitalize` makes the first character of your string capitalized.
|
`capitalize` makes the first character of your string capitalized.
|
||||||
|
|
||||||
| Input | Output |
|
```liquid
|
||||||
|:-----------------------------------------------------------|:-----------------|
|
{% raw %}
|
||||||
| {% raw %}`{{ "title" | capitalize }}` {% endraw %} | "Title" |
|
{{ "title" | capitalize }}
|
||||||
| {% raw %}`{{ "my great title" | capitalize }}`{% endraw %} | "My great title" |
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
It only capitalizes the first character, so subsequent words will not be capitalized as well.
|
```text
|
||||||
|
Title
|
||||||
|
```
|
||||||
|
|
||||||
|
`capitalize` only capitalizes the first character of the string, so subsequent words are not affected:
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{% raw %}
|
||||||
|
{{ "my great title" | capitalize }}
|
||||||
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
My great title
|
||||||
|
```
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,8 @@
|
|||||||
---
|
---
|
||||||
title: ceil
|
title: ceil
|
||||||
layout: default
|
layout: method
|
||||||
|
examples:
|
||||||
|
- 1.2
|
||||||
---
|
---
|
||||||
|
|
||||||
`ceil` rounds the input up to the nearest whole number.
|
`ceil` rounds the input up to the nearest whole number.
|
||||||
|
|||||||
+29
-7
@@ -2,21 +2,43 @@
|
|||||||
title: default
|
title: default
|
||||||
---
|
---
|
||||||
|
|
||||||
`default` offers a means of having a fallback in case your value doesn't exist.
|
`default` offers a means of having a fallback in case your value doesn't exist. `default` will use its substitute if the left side is `nil`, `false`, or empty.
|
||||||
|
|
||||||
{% highlight liquid %}
|
In this example, `product_price` is not defined, so the default value is used.
|
||||||
|
|
||||||
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
{{ product_price | default: 2.99 }}
|
{{ product_price | default: 2.99 }}
|
||||||
// => outputs "2.99"
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
2.99
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example, `product_price` is defined, so the default value is not used.
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{% raw %}
|
||||||
{% assign product_price = 4.99 %}
|
{% assign product_price = 4.99 %}
|
||||||
{{ product_price | default:2.99 }}
|
{{ product_price | default:2.99 }}
|
||||||
// => outputs "4.99"
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
4.99
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example, `product_price` is empty, so the default value is used.
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{% raw %}
|
||||||
{% assign product_price = "" %}
|
{% assign product_price = "" %}
|
||||||
{{ product_price | default: 2.99 }}
|
{{ product_price | default: 2.99 }}
|
||||||
// => outputs "2.99"
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
{% endhighlight %}
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
2.99
|
||||||
|
```
|
||||||
|
|
||||||
`default` will use its substitute if the left side is `nil`, `false`, or empty.
|
|
||||||
|
|||||||
+46
-56
@@ -4,10 +4,10 @@ title: Control flow
|
|||||||
|
|
||||||
## case/when
|
## case/when
|
||||||
|
|
||||||
<p>Creates a switch statement to compare a variable with different values. <code>case</code> initializes the switch statement, and <code>when</code> compares its values.</p>
|
Creates a switch statement to compare a variable with different values. `case` initializes the switch statement, and `when` compares its values.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% raw %}
|
{% raw %}
|
||||||
{% assign handle = 'cake' %}
|
{% assign handle = 'cake' %}
|
||||||
{% case handle %}
|
{% case handle %}
|
||||||
{% when 'cake' %}
|
{% when 'cake' %}
|
||||||
@@ -17,82 +17,72 @@ title: Control flow
|
|||||||
{% else %}
|
{% else %}
|
||||||
This is not a cake nor a cookie
|
This is not a cake nor a cookie
|
||||||
{% endcase %}
|
{% endcase %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
This is a cake
|
This is a cake
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
## if
|
## if
|
||||||
|
|
||||||
<p>Executes a block of code only if a certain condition is met.</p>
|
Executes a block of code only if a certain condition is met.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% raw %}
|
{% raw %}
|
||||||
{% if product.title == 'Awesome Shoes' %}
|
{% if product.title == 'Awesome Shoes' %}
|
||||||
These shoes are awesome!
|
These shoes are awesome!
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
<div class="code-block code-block--output">
|
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
These shoes are awesome!
|
These shoes are awesome!
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
## elsif / else
|
## elsif / else
|
||||||
|
|
||||||
<p>Adds more conditions within an <code>if</code> or <code>unless</code> block.</p>
|
Adds more conditions within an `if` or `unless` block.
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{% raw %}
|
||||||
|
<!-- If customer.name = 'anonymous' -->
|
||||||
|
{% if customer.name == 'kevin' %}
|
||||||
|
Hey Kevin!
|
||||||
|
{% elsif customer.name == 'anonymous' %}
|
||||||
|
Hey Anonymous!
|
||||||
|
{% else %}
|
||||||
|
Hi Stranger!
|
||||||
|
{% endif %}
|
||||||
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```text
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<!-- If customer.name = 'anonymous' -->
|
|
||||||
{% if customer.name == 'kevin' %}
|
|
||||||
Hey Kevin!
|
|
||||||
{% elsif customer.name == 'anonymous' %}
|
|
||||||
Hey Anonymous!
|
|
||||||
{% else %}
|
|
||||||
Hi Stranger!
|
|
||||||
{% endif %}
|
|
||||||
{% endraw %}{% endhighlight %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
Hey Anonymous!
|
Hey Anonymous!
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
## unless
|
## unless
|
||||||
|
|
||||||
<p>Similar to <code>if</code>, but executes a block of code only if a certain condition is <strong>not</strong> met.</p>
|
Similar to `if`, but executes a block of code only if a certain condition is **not** met.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% raw %}
|
{% raw %}
|
||||||
{% unless product.title == 'Awesome Shoes' %}
|
{% unless product.title == 'Awesome Shoes' %}
|
||||||
These shoes are not awesome.
|
These shoes are not awesome.
|
||||||
{% endunless %}
|
{% endunless %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```text
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
These shoes are not awesome.
|
These shoes are not awesome.
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
This would be the equivalent of doing the following:
|
This would be the equivalent of doing the following:
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```liquid
|
||||||
{% highlight html %}{% raw %}
|
{% raw %}
|
||||||
{% if product.title != 'Awesome Shoes' %}
|
{% if product.title != 'Awesome Shoes' %}
|
||||||
These shoes are not awesome.
|
These shoes are not awesome.
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|||||||
+163
-293
@@ -4,116 +4,106 @@ title: Iteration
|
|||||||
|
|
||||||
Iteration Tags are used to run a block of code repeatedly.
|
Iteration Tags are used to run a block of code repeatedly.
|
||||||
|
|
||||||
### for
|
## for
|
||||||
|
|
||||||
Repeatedly executes a block of code. For a full list of attributes available within a `for` loop, see [forloop (object)](/themes/liquid-documentation/objects/for-loops).
|
Repeatedly executes a block of code. For a full list of attributes available within a `for` loop, see [forloop (object)](/themes/liquid-documentation/objects/for-loops).
|
||||||
|
|
||||||
`for` loops can output a maximum of 50 results per page. In cases where there are more than 50 results, use the [paginate](/themes/liquid-documentation/tags/theme-tags/#paginate) tag to split them across multiple pages.
|
`for` loops can output a maximum of 50 results per page. In cases where there are more than 50 results, use the [paginate](/themes/liquid-documentation/tags/theme-tags/#paginate) tag to split them across multiple pages.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight liquid %}{% raw %}
|
{% raw %}
|
||||||
{% for product in collection.products %}
|
{% for product in collection.products %}
|
||||||
{{ product.title }}
|
{{ product.title }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight text %}
|
|
||||||
hat shirt pants
|
hat shirt pants
|
||||||
{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
### break
|
### break
|
||||||
|
|
||||||
Causes the loop to stop iterating when it encounters the `break` tag.
|
Causes the loop to stop iterating when it encounters the `break` tag.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight liquid %}{% raw %}
|
{% raw %}
|
||||||
{% for i in (1..5) %}
|
{% for i in (1..5) %}
|
||||||
{% if i == 4 %}
|
{% if i == 4 %}
|
||||||
{% break %}
|
{% break %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ i }}
|
{{ i }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight text %}
|
|
||||||
1 2 3
|
1 2 3
|
||||||
{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
### continue
|
### continue
|
||||||
|
|
||||||
Causes the loop to skip the current iteration when it encounters the `continue` tag.
|
Causes the loop to skip the current iteration when it encounters the `continue` tag.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight liquid %}{% raw %}
|
{% raw %}
|
||||||
{% for i in (1..5) %}
|
{% for i in (1..5) %}
|
||||||
{% if i == 4 %}
|
{% if i == 4 %}
|
||||||
{% continue %}
|
{% continue %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ i }}
|
{{ i }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight text %}
|
|
||||||
1 2 3 5
|
1 2 3 5
|
||||||
{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="sub-sub-section">
|
### for parameters
|
||||||
|
|
||||||
<h2 class="parameter">parameters <span>for</span></h2>
|
#### limit
|
||||||
|
|
||||||
<h4>limit</h4>
|
|
||||||
Exits the for loop at a specific index.
|
Exits the for loop at a specific index.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% 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 }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
1 2
|
1 2
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
|
#### offset
|
||||||
|
|
||||||
<h4>offset</h4>
|
|
||||||
Starts the for loop at a specific index.
|
Starts the for loop at a specific index.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% 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 }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
3 4 5 6
|
3 4 5 6
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
#### range
|
||||||
|
|
||||||
<h4>range</h4>
|
|
||||||
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.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% raw %}
|
{% raw %}
|
||||||
{% assign num = 4 %}
|
{% assign num = 4 %}
|
||||||
{% for i in (1..num) %}
|
{% for i in (1..num) %}
|
||||||
{{ i }}
|
{{ i }}
|
||||||
@@ -122,290 +112,174 @@ Defines a range of numbers to loop through. The range can be defined by both lit
|
|||||||
{% for i in (3..5) %}
|
{% for i in (3..5) %}
|
||||||
{{ i }}
|
{{ i }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
1 2 3 4
|
1 2 3 4
|
||||||
3 4 5
|
3 4 5
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
#### reversed
|
||||||
|
|
||||||
<h4>reversed
|
|
||||||
</h4>
|
|
||||||
Reverses the order of the for loop.
|
Reverses the order of the for loop.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% 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 }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
6 5 4 3 2 1
|
6 5 4 3 2 1
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
### cycle
|
## cycle
|
||||||
|
|
||||||
Loops through a group of strings and outputs them in the order that they were passed as parameters. Each time <code>cycle</code> is called, the next string that was passed as a parameter is output.
|
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.
|
||||||
|
|
||||||
<code>cycle</code> must be used within a <a href="#for">for</a> loop block.
|
`cycle` must be used within a [for](#for) loop block.
|
||||||
|
|
||||||
|
```liquid
|
||||||
<div class="code-block code-block--input">
|
{% raw %}
|
||||||
{% highlight html %}{% 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' %}
|
||||||
{% cycle 'one', 'two', 'three' %}
|
{% cycle 'one', 'two', 'three' %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```text
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
one
|
one
|
||||||
two
|
two
|
||||||
three
|
three
|
||||||
one
|
one
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
Uses for <code>cycle</code> include:
|
|
||||||
|
|
||||||
- applying odd/even classes to rows in a table
|
|
||||||
- applying a unique class to the last product thumbnail in a row
|
|
||||||
|
|
||||||
<div class="sub-sub-section">
|
|
||||||
|
|
||||||
<h2 class="parameter">parameters <span>cycle</span></h2>
|
|
||||||
|
|
||||||
<code>cycle</code> accepts a parameter called <strong>cycle group</strong> in cases where you need multiple <code>cycle</code> 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>The example below shows why cycle groups are necessary when there are multiple instances of the cycle block.</p>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<ul>
|
|
||||||
{% for product in collections.collection-1.products %}
|
|
||||||
<li{% cycle ' style="clear:both;"', '', '', ' class="last"' %}>
|
|
||||||
<a href="{{ product.url | within: collection }}">
|
|
||||||
<img src="{{ product.featured_image.src | product_img_url: 'medium' }}" alt="{{ product.featured_image.alt }}" />
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
{% for product in collections.collection-2.products %}
|
|
||||||
<li{% cycle ' style="clear:both;"', '', '', ' class="last"' %}>
|
|
||||||
<a href="{{ product.url | within: collection }}">
|
|
||||||
<img src="{{ product.featured_image.src | product_img_url: 'medium' }}" alt="{{ product.featured_image.alt }}" />
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% endraw %}{% endhighlight %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>In the code above, if the first collection only has two products, the second collection loop will continue the <code>cycle</code> where the first one left off. This will result in this undesired output:</p>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<ul>
|
|
||||||
<li style="clear:both"></li>
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
<li></li>
|
|
||||||
<li class="last"></li>
|
|
||||||
<li style="clear:both"></li>
|
|
||||||
<li></li>
|
|
||||||
</ul>
|
|
||||||
{% endraw %}{% endhighlight %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>To avoid this, cycle groups are used for each <code>cycle</code> block, as shown below.</p>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<ul>
|
|
||||||
{% for product in collections.collection-1.products %}
|
|
||||||
<li{% cycle 'group1': ' style="clear:both;"', '', '', ' class="last"' %}>
|
|
||||||
<a href="{{ product.url | within: collection }}">
|
|
||||||
<img src="{{ product.featured_image.src | product_img_url: "medium" }}" alt="{{ product.featured_image.alt }}" />
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
{% for product in collections.collection-2.products %}
|
|
||||||
<li{% cycle 'group2': ' style="clear:both;"', '', '', ' class="last"' %}>
|
|
||||||
<a href="{{ product.url | within: collection }}">
|
|
||||||
<img src="{{ product.featured_image.src | product_img_url: "medium" }}" alt="{{ product.featured_image.alt }}" />
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% endraw %}{% endhighlight %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>With the code above, the two <code>cycle</code> blocks are independent of each other. The result is shown below:</p>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<ul>
|
|
||||||
<li style="clear:both"></li>
|
|
||||||
<li></li>
|
|
||||||
</ul>
|
|
||||||
<!-- new cycle group starts! -->
|
|
||||||
<ul>
|
|
||||||
<li style="clear:both"></li>
|
|
||||||
<li></li>
|
|
||||||
<li></li>
|
|
||||||
<li class="last"></li>
|
|
||||||
</ul>
|
|
||||||
{% endraw %}{% endhighlight %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
### 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.
|
||||||
|
|
||||||
### tablerow
|
### tablerow
|
||||||
|
|
||||||
<p>Generates an HTML <code><table></code>. Must be wrapped in an opening <table> and closing </table> HTML tags. For a full list of attributes available within a tablerow loop, see <a href="/themes/liquid-documentation/objects/tablerow">tablerow (object)</a>.</p>
|
Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` HTML tags.
|
||||||
|
|
||||||
|
```liquid
|
||||||
<div class="code-block code-block--input">
|
{% raw %}
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<table>
|
<table>
|
||||||
{% tablerow product in collection.products %}
|
{% tablerow product in collection.products %}
|
||||||
{{ product.title }}
|
{{ product.title }}
|
||||||
{% endtablerow %}
|
{% endtablerow %}
|
||||||
</table>
|
</table>
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```html
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<table>
|
<table>
|
||||||
<tr class="row1">
|
<tr class="row1">
|
||||||
<td class="col1">
|
<td class="col1">
|
||||||
Cool Shirt
|
Cool Shirt
|
||||||
</td>
|
</td>
|
||||||
<td class="col2">
|
<td class="col2">
|
||||||
Alien Poster
|
Alien Poster
|
||||||
</td>
|
</td>
|
||||||
<td class="col3">
|
<td class="col3">
|
||||||
Batman Poster
|
Batman Poster
|
||||||
</td>
|
</td>
|
||||||
<td class="col4">
|
<td class="col4">
|
||||||
Bullseye Shirt
|
Bullseye Shirt
|
||||||
</td>
|
</td>
|
||||||
<td class="col5">
|
<td class="col5">
|
||||||
Another Classic Vinyl
|
Another Classic Vinyl
|
||||||
</td>
|
</td>
|
||||||
<td class="col6">
|
<td class="col6">
|
||||||
Awesome Jeans
|
Awesome Jeans
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
|
### tablerow parameters
|
||||||
|
|
||||||
<div class="sub-sub-section">
|
#### cols
|
||||||
|
|
||||||
<h2 class="parameter">parameters <span>tablerow</span></h2>
|
|
||||||
|
|
||||||
<h4>cols</h4>
|
|
||||||
|
|
||||||
Defines how many columns the tables should have.
|
Defines how many columns the tables should have.
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
```liquid
|
||||||
{% highlight html %}{% raw %}
|
{% raw %}
|
||||||
{% tablerow product in collection.products cols:2 %}
|
{% tablerow product in collection.products cols:2 %}
|
||||||
{{ product.title }}
|
{{ product.title }}
|
||||||
{% endtablerow %}
|
{% endtablerow %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
```html
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<table>
|
<table>
|
||||||
<tr class="row1">
|
<tr class="row1">
|
||||||
<td class="col1">
|
<td class="col1">
|
||||||
Cool Shirt
|
Cool Shirt
|
||||||
</td>
|
</td>
|
||||||
<td class="col2">
|
<td class="col2">
|
||||||
Alien Poster
|
Alien Poster
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="row2">
|
<tr class="row2">
|
||||||
<td class="col1">
|
<td class="col1">
|
||||||
Batman Poster
|
Batman Poster
|
||||||
</td>
|
</td>
|
||||||
<td class="col2">
|
<td class="col2">
|
||||||
Bullseye Shirt
|
Bullseye Shirt
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="row3">
|
<tr class="row3">
|
||||||
<td class="col1">
|
<td class="col1">
|
||||||
Another Classic Vinyl
|
Another Classic Vinyl
|
||||||
</td>
|
</td>
|
||||||
<td class="col2">
|
<td class="col2">
|
||||||
Awesome Jeans
|
Awesome Jeans
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
{% endraw %}{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
<h4>limit</h4>
|
#### limit
|
||||||
|
|
||||||
Exits the tablerow after a specific index.
|
Exits the tablerow after a specific index.
|
||||||
<br/><br/>
|
|
||||||
<div>
|
```liquid
|
||||||
{% highlight html %}{% 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 %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
|
#### offset
|
||||||
<h4>offset</h4>
|
|
||||||
|
|
||||||
Starts the tablerow after a specific index.
|
Starts the tablerow after a specific index.
|
||||||
<br/><br/>
|
|
||||||
<div>
|
```liquid
|
||||||
{% highlight html %}{% 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 %}
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
|
#### range
|
||||||
<h4>range</h4>
|
|
||||||
|
|
||||||
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.
|
||||||
<br/><br/>
|
|
||||||
|
|
||||||
|
```liquid
|
||||||
<div>
|
{% raw %}
|
||||||
{% highlight html %}{% raw %}
|
|
||||||
<!--variable number example-->
|
<!--variable number example-->
|
||||||
|
|
||||||
{% assign num = 4 %}
|
{% assign num = 4 %}
|
||||||
@@ -422,9 +296,5 @@ Defines a range of numbers to loop through. The range can be defined by both lit
|
|||||||
{{ i }}
|
{{ i }}
|
||||||
{% endtablerow %}
|
{% endtablerow %}
|
||||||
</table>
|
</table>
|
||||||
{% endraw %}{% endhighlight %}
|
{% endraw %}
|
||||||
</div>
|
```
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user