mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Compare commits
40 Commits
gh-pages-t
...
gh-pages
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e19019517a | ||
|
|
b98d3d6097 | ||
|
|
77c2dfa989 | ||
|
|
d8f5d65e32 | ||
|
|
c2fab68b85 | ||
|
|
c99ddcbfc8 | ||
|
|
fb8432ca16 | ||
|
|
1b53edf052 | ||
|
|
b318616a97 | ||
|
|
fc5d02fe1c | ||
|
|
0f83e333c4 | ||
|
|
09e4fef712 | ||
|
|
9e0dc135ca | ||
|
|
d4222ff2b6 | ||
|
|
c4dce51f62 | ||
|
|
9542f1d961 | ||
|
|
32a327ed30 | ||
|
|
e47ea38940 | ||
|
|
537f53ef7c | ||
|
|
bcf72e42d2 | ||
|
|
7cfa4aa8bc | ||
|
|
cd467810fb | ||
|
|
109a1fe88a | ||
|
|
67f086040a | ||
|
|
aa6240f43c | ||
|
|
40bf603bfb | ||
|
|
ca2050446c | ||
|
|
506df22f41 | ||
|
|
c63fcdfe0a | ||
|
|
95dca87f49 | ||
|
|
6a01c98702 | ||
|
|
515ea65511 | ||
|
|
a136b74803 | ||
|
|
adf59df3d9 | ||
|
|
40ab3ef17c | ||
|
|
bea649dc63 | ||
|
|
ea6b176363 | ||
|
|
9ff1b88985 | ||
|
|
4cfd19a27e | ||
|
|
29d3ac003a |
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
# http://editorconfig.org/
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = true
|
||||
20
.github/workflows/docs.yml
vendored
Normal file
20
.github/workflows/docs.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Build Docs
|
||||
|
||||
on:
|
||||
push: {}
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: github.event_name == 'push' || github.event.pull_request.head.repo.owner.login != 'Shopify'
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: '2.7.1'
|
||||
bundler-cache: true
|
||||
- run: bundle exec jekyll build --trace
|
||||
17
.travis.yml
17
.travis.yml
@@ -1,17 +0,0 @@
|
||||
sudo: false
|
||||
language: ruby
|
||||
cache: bundler
|
||||
rvm: 2.4
|
||||
|
||||
before_install:
|
||||
- gem update --system
|
||||
install: bundle install
|
||||
script: bundle exec jekyll build --trace
|
||||
|
||||
branches:
|
||||
only:
|
||||
- gh-pages
|
||||
|
||||
env:
|
||||
global:
|
||||
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
|
||||
1
Gemfile
1
Gemfile
@@ -1,3 +1,4 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'github-pages', '>=180', group: :jekyll_plugins
|
||||
gem 'wdm', '>= 0.1.0' if Gem.win_platform?
|
||||
|
||||
248
Gemfile.lock
248
Gemfile.lock
@@ -1,248 +0,0 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
activesupport (4.2.10)
|
||||
i18n (~> 0.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
addressable (2.5.2)
|
||||
public_suffix (>= 2.0.2, < 4.0)
|
||||
coffee-script (2.4.1)
|
||||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.11.1)
|
||||
colorator (1.1.0)
|
||||
commonmarker (0.17.13)
|
||||
ruby-enum (~> 0.5)
|
||||
concurrent-ruby (1.0.5)
|
||||
dnsruby (1.61.2)
|
||||
addressable (~> 2.5)
|
||||
em-websocket (0.5.1)
|
||||
eventmachine (>= 0.12.9)
|
||||
http_parser.rb (~> 0.6.0)
|
||||
ethon (0.11.0)
|
||||
ffi (>= 1.3.0)
|
||||
eventmachine (1.2.7)
|
||||
execjs (2.7.0)
|
||||
faraday (0.15.3)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.9.25)
|
||||
forwardable-extended (2.6.0)
|
||||
gemoji (3.0.0)
|
||||
github-pages (192)
|
||||
activesupport (= 4.2.10)
|
||||
github-pages-health-check (= 1.8.1)
|
||||
jekyll (= 3.7.4)
|
||||
jekyll-avatar (= 0.6.0)
|
||||
jekyll-coffeescript (= 1.1.1)
|
||||
jekyll-commonmark-ghpages (= 0.1.5)
|
||||
jekyll-default-layout (= 0.1.4)
|
||||
jekyll-feed (= 0.10.0)
|
||||
jekyll-gist (= 1.5.0)
|
||||
jekyll-github-metadata (= 2.9.4)
|
||||
jekyll-mentions (= 1.4.1)
|
||||
jekyll-optional-front-matter (= 0.3.0)
|
||||
jekyll-paginate (= 1.1.0)
|
||||
jekyll-readme-index (= 0.2.0)
|
||||
jekyll-redirect-from (= 0.14.0)
|
||||
jekyll-relative-links (= 0.5.3)
|
||||
jekyll-remote-theme (= 0.3.1)
|
||||
jekyll-sass-converter (= 1.5.2)
|
||||
jekyll-seo-tag (= 2.5.0)
|
||||
jekyll-sitemap (= 1.2.0)
|
||||
jekyll-swiss (= 0.4.0)
|
||||
jekyll-theme-architect (= 0.1.1)
|
||||
jekyll-theme-cayman (= 0.1.1)
|
||||
jekyll-theme-dinky (= 0.1.1)
|
||||
jekyll-theme-hacker (= 0.1.1)
|
||||
jekyll-theme-leap-day (= 0.1.1)
|
||||
jekyll-theme-merlot (= 0.1.1)
|
||||
jekyll-theme-midnight (= 0.1.1)
|
||||
jekyll-theme-minimal (= 0.1.1)
|
||||
jekyll-theme-modernist (= 0.1.1)
|
||||
jekyll-theme-primer (= 0.5.3)
|
||||
jekyll-theme-slate (= 0.1.1)
|
||||
jekyll-theme-tactile (= 0.1.1)
|
||||
jekyll-theme-time-machine (= 0.1.1)
|
||||
jekyll-titles-from-headings (= 0.5.1)
|
||||
jemoji (= 0.10.1)
|
||||
kramdown (= 1.17.0)
|
||||
liquid (= 4.0.0)
|
||||
listen (= 3.1.5)
|
||||
mercenary (~> 0.3)
|
||||
minima (= 2.5.0)
|
||||
nokogiri (>= 1.8.2, < 2.0)
|
||||
rouge (= 2.2.1)
|
||||
terminal-table (~> 1.4)
|
||||
github-pages-health-check (1.8.1)
|
||||
addressable (~> 2.3)
|
||||
dnsruby (~> 1.60)
|
||||
octokit (~> 4.0)
|
||||
public_suffix (~> 2.0)
|
||||
typhoeus (~> 1.3)
|
||||
html-pipeline (2.8.4)
|
||||
activesupport (>= 2)
|
||||
nokogiri (>= 1.4)
|
||||
http_parser.rb (0.6.0)
|
||||
i18n (0.9.5)
|
||||
concurrent-ruby (~> 1.0)
|
||||
jekyll (3.7.4)
|
||||
addressable (~> 2.4)
|
||||
colorator (~> 1.0)
|
||||
em-websocket (~> 0.5)
|
||||
i18n (~> 0.7)
|
||||
jekyll-sass-converter (~> 1.0)
|
||||
jekyll-watch (~> 2.0)
|
||||
kramdown (~> 1.14)
|
||||
liquid (~> 4.0)
|
||||
mercenary (~> 0.3.3)
|
||||
pathutil (~> 0.9)
|
||||
rouge (>= 1.7, < 4)
|
||||
safe_yaml (~> 1.0)
|
||||
jekyll-avatar (0.6.0)
|
||||
jekyll (~> 3.0)
|
||||
jekyll-coffeescript (1.1.1)
|
||||
coffee-script (~> 2.2)
|
||||
coffee-script-source (~> 1.11.1)
|
||||
jekyll-commonmark (1.2.0)
|
||||
commonmarker (~> 0.14)
|
||||
jekyll (>= 3.0, < 4.0)
|
||||
jekyll-commonmark-ghpages (0.1.5)
|
||||
commonmarker (~> 0.17.6)
|
||||
jekyll-commonmark (~> 1)
|
||||
rouge (~> 2)
|
||||
jekyll-default-layout (0.1.4)
|
||||
jekyll (~> 3.0)
|
||||
jekyll-feed (0.10.0)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-gist (1.5.0)
|
||||
octokit (~> 4.2)
|
||||
jekyll-github-metadata (2.9.4)
|
||||
jekyll (~> 3.1)
|
||||
octokit (~> 4.0, != 4.4.0)
|
||||
jekyll-mentions (1.4.1)
|
||||
html-pipeline (~> 2.3)
|
||||
jekyll (~> 3.0)
|
||||
jekyll-optional-front-matter (0.3.0)
|
||||
jekyll (~> 3.0)
|
||||
jekyll-paginate (1.1.0)
|
||||
jekyll-readme-index (0.2.0)
|
||||
jekyll (~> 3.0)
|
||||
jekyll-redirect-from (0.14.0)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-relative-links (0.5.3)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-remote-theme (0.3.1)
|
||||
jekyll (~> 3.5)
|
||||
rubyzip (>= 1.2.1, < 3.0)
|
||||
jekyll-sass-converter (1.5.2)
|
||||
sass (~> 3.4)
|
||||
jekyll-seo-tag (2.5.0)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-sitemap (1.2.0)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-swiss (0.4.0)
|
||||
jekyll-theme-architect (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-cayman (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-dinky (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-hacker (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-leap-day (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-merlot (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-midnight (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-minimal (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-modernist (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-primer (0.5.3)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-github-metadata (~> 2.9)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-slate (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-tactile (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-time-machine (0.1.1)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-titles-from-headings (0.5.1)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-watch (2.0.0)
|
||||
listen (~> 3.0)
|
||||
jemoji (0.10.1)
|
||||
gemoji (~> 3.0)
|
||||
html-pipeline (~> 2.2)
|
||||
jekyll (~> 3.0)
|
||||
kramdown (1.17.0)
|
||||
liquid (4.0.0)
|
||||
listen (3.1.5)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
ruby_dep (~> 1.2)
|
||||
mercenary (0.3.6)
|
||||
mini_portile2 (2.3.0)
|
||||
minima (2.5.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-feed (~> 0.9)
|
||||
jekyll-seo-tag (~> 2.1)
|
||||
minitest (5.11.3)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.8.4)
|
||||
mini_portile2 (~> 2.3.0)
|
||||
octokit (4.12.0)
|
||||
sawyer (~> 0.8.0, >= 0.5.3)
|
||||
pathutil (0.16.1)
|
||||
forwardable-extended (~> 2.6)
|
||||
public_suffix (2.0.5)
|
||||
rb-fsevent (0.10.3)
|
||||
rb-inotify (0.9.10)
|
||||
ffi (>= 0.5.0, < 2)
|
||||
rouge (2.2.1)
|
||||
ruby-enum (0.7.2)
|
||||
i18n
|
||||
ruby_dep (1.5.0)
|
||||
rubyzip (1.2.2)
|
||||
safe_yaml (1.0.4)
|
||||
sass (3.6.0)
|
||||
sass-listen (~> 4.0.0)
|
||||
sass-listen (4.0.0)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
sawyer (0.8.1)
|
||||
addressable (>= 2.3.5, < 2.6)
|
||||
faraday (~> 0.8, < 1.0)
|
||||
terminal-table (1.8.0)
|
||||
unicode-display_width (~> 1.1, >= 1.1.1)
|
||||
thread_safe (0.3.6)
|
||||
typhoeus (1.3.0)
|
||||
ethon (>= 0.9.0)
|
||||
tzinfo (1.2.5)
|
||||
thread_safe (~> 0.1)
|
||||
unicode-display_width (1.4.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
github-pages (>= 180)
|
||||
|
||||
BUNDLED WITH
|
||||
1.16.5
|
||||
12
README.md
12
README.md
@@ -2,8 +2,10 @@
|
||||
|
||||
To run, follow these steps:
|
||||
|
||||
1. Download ZIP or clone in GitHub
|
||||
2. Navigate to `liquid` folder
|
||||
3. Run `jekyll watch`
|
||||
4. Open `http://127.0.0.1:4000` in your browser
|
||||
|
||||
1. [Download and install Ruby](https://www.ruby-lang.org/en/downloads)
|
||||
2. Download ZIP or clone in GitHub
|
||||
3. Navigate to `liquid-gh-pages` folder or checkout `gh-pages` branch
|
||||
4. Run `gem install bundler`
|
||||
5. Run `bundle install`
|
||||
6. Run `bundle exec jekyll serve`
|
||||
7. Open [`http://127.0.0.1:4000/liquid/`](http://127.0.0.1:4000/liquid/) in your browser
|
||||
|
||||
@@ -4,36 +4,33 @@ description: An overview of objects, tags, and filters in the Liquid template la
|
||||
redirect_from: /basics/
|
||||
---
|
||||
|
||||
Liquid code can be categorized into [**objects**](#objects), [**tags**](#tags), and [**filters**](#filters).
|
||||
Liquid uses a combination of [**objects**](#objects), [**tags**](#tags), and [**filters**](#filters) inside **template files** to display dynamic content.
|
||||
|
||||
## Objects
|
||||
|
||||
**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 %}`.
|
||||
|
||||
**Objects** contain the content that Liquid displays on a page. Objects and variables are displayed when enclosed in double curly braces: `{% raw %}{{{% endraw %}` and `{% raw %}}}{% endraw %}`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ page.title }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
Introduction
|
||||
{{ page.title }}
|
||||
```
|
||||
|
||||
In this case, Liquid is rendering the content of an object called `page.title`, and that object contains the text `Introduction`.
|
||||
In this case, Liquid is rendering the content of the `title` property of the `page` object, which contains the text `{{ page.title }}`.
|
||||
|
||||
## Tags
|
||||
|
||||
**Tags** create the logic and control flow for templates. They are denoted by curly braces and percent signs: `{% raw %}{%{% endraw %}` and `{% raw %}%}{% endraw %}`.
|
||||
|
||||
The markup used in tags does not produce any visible text. This means that you can assign variables and create conditions and loops without showing any of the Liquid logic on the page.
|
||||
**Tags** create the logic and control flow for templates. The curly brace percentage delimiters `{% raw %}{%{% endraw %}` and `{% raw %}%}{% endraw %}` and the text that they surround do not produce any visible output when the template is rendered. This lets you assign variables and create conditions or loops without showing any of the Liquid logic on the page.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% if user %}
|
||||
Hello {{ user.name }}!
|
||||
{% endif %}
|
||||
@@ -42,25 +39,25 @@ The markup used in tags does not produce any visible text. This means that you c
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
Hello Adam!
|
||||
Hello Adam!
|
||||
```
|
||||
|
||||
Tags can be categorized into three types:
|
||||
Tags can be categorized into various types:
|
||||
|
||||
- [Control flow]({{ "/tags/control-flow" | prepend: site.baseurl }})
|
||||
- [Iteration]({{ "/tags/iteration" | prepend: site.baseurl }})
|
||||
- [Variable assignments]({{ "/tags/variable" | prepend: site.baseurl }})
|
||||
- [Control flow]({{ "/tags/control-flow/" | prepend: site.baseurl }})
|
||||
- [Iteration]({{ "/tags/iteration/" | prepend: site.baseurl }})
|
||||
- [Template]({{ "/tags/template/" | prepend: site.baseurl }})
|
||||
- [Variable assignment]({{ "/tags/variable/" | prepend: site.baseurl }})
|
||||
|
||||
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 `|`.
|
||||
**Filters** change the output of a Liquid object or variable. They are used within double curly braces `{% raw %}{{ }}{% endraw %}` and [variable assignment]({{ "/tags/variable/" | prepend: site.baseurl }}), and are separated by a pipe character `|`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "/my/fancy/url" | append: ".html" }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -70,16 +67,16 @@ You can read more about each type of tag in their respective sections.
|
||||
{{ "/my/fancy/url" | append: ".html" }}
|
||||
```
|
||||
|
||||
Multiple filters can be used on one output. They are applied from left to right.
|
||||
Multiple filters can be used on one output, and are applied from left to right.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "adam!" | capitalize | prepend: "Hello " }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
Hello Adam!
|
||||
{{ "adam!" | capitalize | prepend: "Hello " }}
|
||||
```
|
||||
|
||||
@@ -3,7 +3,7 @@ title: Operators
|
||||
description: Using operators to perform calculations in the Liquid template language.
|
||||
---
|
||||
|
||||
Liquid includes many logical and comparison operators.
|
||||
Liquid includes many logical and comparison operators. You can use operators to create logic with [control flow]({{ "/tags/control-flow/" | prepend: site.baseurl }}) tags.
|
||||
|
||||
## Basic operators
|
||||
|
||||
@@ -47,17 +47,17 @@ Liquid includes many logical and comparison operators.
|
||||
For example:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% if product.title == "Awesome Shoes" %}
|
||||
These shoes are awesome!
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
You can use multiple operators in a tag:
|
||||
You can do multiple comparisons in a tag using the `and` and `or` operators:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% if product.type == "Shirt" or product.type == "Shoes" %}
|
||||
This is a shirt or a pair of shoes.
|
||||
{% endif %}
|
||||
@@ -69,8 +69,8 @@ You can use multiple operators in a tag:
|
||||
`contains` checks for the presence of a substring inside a string.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% if product.title contains 'Pack' %}
|
||||
{%- raw -%}
|
||||
{% if product.title contains "Pack" %}
|
||||
This product's title contains the word Pack.
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
@@ -79,9 +79,9 @@ You can use multiple operators in a tag:
|
||||
`contains` can also check for the presence of a string in an array of strings.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% if product.tags contains 'Hello' %}
|
||||
This product has been tagged with 'Hello'.
|
||||
{%- raw -%}
|
||||
{% if product.tags contains "Hello" %}
|
||||
This product has been tagged with "Hello".
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -93,15 +93,15 @@ You can use multiple operators in a tag:
|
||||
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
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% 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 %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% if true and false and false or true %}
|
||||
This evaluates to false, since the tags are checked like this:
|
||||
|
||||
|
||||
@@ -3,47 +3,43 @@ title: Truthy and falsy
|
||||
description: An overview of boolean logic in the Liquid template language.
|
||||
---
|
||||
|
||||
In programming, anything that returns `true` in a conditional is called **truthy**. Anything that returns `false` in a conditional is called **falsy**. All object types can be described as either truthy or falsy.
|
||||
|
||||
- [Truthy](#truthy)
|
||||
- [Falsy](#falsy)
|
||||
- [Summary](#summary)
|
||||
When a non-boolean [data type]({{ "/basics/types/" | prepend: site.baseurl }}) is used in a boolean context (such as a conditional tag), Liquid decides whether to evaluate it as `true` or `false`. Data types that return `true` by default are called **truthy**. Data types that return false by default are called **falsy**.
|
||||
|
||||
## Truthy
|
||||
|
||||
All values in Liquid are truthy except `nil` and `false`.
|
||||
|
||||
In the example below, the string "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
|
||||
{% raw %}
|
||||
{% assign tobi = "Tobi" %}
|
||||
{%- raw -%}
|
||||
{% assign name = "Tobi" %}
|
||||
|
||||
{% if tobi %}
|
||||
This condition will always be true.
|
||||
{% if name %}
|
||||
This text will always appear since "name" is defined.
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
[Strings]({{ "/basics/types/#string" | prepend: site.baseurl }}), even when empty, are truthy. The example below will result in empty HTML tags if `settings.fp_heading` is empty:
|
||||
[Strings]({{ "/basics/types/#string" | prepend: site.baseurl }}), even when empty, are truthy. The example below will create empty HTML tags if `page.category` exists but is empty:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% if settings.fp_heading %}
|
||||
<h1>{{ settings.fp_heading }}</h1>
|
||||
{%- raw -%}
|
||||
{% if page.category %}
|
||||
<h1>{{ page.category }}</h1>
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```html
|
||||
<h1></h1>
|
||||
<h1></h1>
|
||||
```
|
||||
|
||||
## Falsy
|
||||
|
||||
The falsy values in Liquid are [`nil`]({{ "/basics/types/#nil" | prepend: site.baseurl }}) and [`false`]({{ "/basics/types/#boolean" | prepend: site.baseurl }}).
|
||||
The only values that are falsy in Liquid are [`nil`]({{ "/basics/types/#nil" | prepend: site.baseurl }}) and [`false`]({{ "/basics/types/#boolean" | prepend: site.baseurl }}).
|
||||
|
||||
## Summary
|
||||
|
||||
|
||||
@@ -3,34 +3,37 @@ title: Types
|
||||
description: An overview of data types in the Liquid template language.
|
||||
---
|
||||
|
||||
Liquid objects can have one of five types:
|
||||
Liquid objects can be one of six types:
|
||||
|
||||
- [String](#string)
|
||||
- [Number](#number)
|
||||
- [Boolean](#boolean)
|
||||
- [Nil](#nil)
|
||||
- [Array](#array)
|
||||
- [EmptyDrop](#emptydrop)
|
||||
|
||||
You can initialize Liquid variables with the [assign]({{ "/tags/variable/#assign" | prepend: site.baseurl }}) or [capture]({{ "/tags/variable/#capture" | prepend: site.baseurl }}) tags.
|
||||
You can initialize Liquid variables using [`assign`]({{ "/tags/variable/#assign" | prepend: site.baseurl }}) or [`capture`]({{ "/tags/variable/#capture" | prepend: site.baseurl }}) tags.
|
||||
|
||||
## String
|
||||
|
||||
Declare a string by wrapping a variable's value in single or double quotes:
|
||||
Strings are sequences of characters wrapped in single or double quotes:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_string = "Hello World!" %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
Liquid does not convert escape sequences into special characters.
|
||||
|
||||
## Number
|
||||
|
||||
Numbers include floats and integers:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_int = 25 %}
|
||||
{% assign my_float = 39.756 %}
|
||||
{% assign my_float = -39.756 %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -39,7 +42,7 @@ Numbers include floats and integers:
|
||||
Booleans are either `true` or `false`. No quotations are necessary when declaring a boolean:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign foo = true %}
|
||||
{% assign bar = false %}
|
||||
{% endraw %}
|
||||
@@ -49,12 +52,12 @@ Booleans are either `true` or `false`. No quotations are necessary when declarin
|
||||
|
||||
Nil is a special empty value that is returned when Liquid code has no results. It is **not** a string with the characters "nil".
|
||||
|
||||
Nil is [treated as false]({{ "/basics/truthy-and-falsy" | prepend: site.baseurl }}) in the conditions of `if` blocks and other Liquid tags that check the truthfulness of a statement.
|
||||
Nil is [treated as false]({{ "/basics/truthy-and-falsy/#falsy" | prepend: site.baseurl }}) in the conditions of `if` blocks and other Liquid tags that check the truthfulness of a statement.
|
||||
|
||||
In the following example, if the user does not exist (that is, `user` returns `nil`), Liquid will not print the greeting:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% if user %}
|
||||
Hello {{ user.name }}!
|
||||
{% endif %}
|
||||
@@ -65,7 +68,7 @@ Tags or outputs that return `nil` will not print anything to the page.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
The current user is {{ user.name }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -81,11 +84,11 @@ Arrays hold lists of variables of any type.
|
||||
|
||||
### Accessing items in arrays
|
||||
|
||||
To access all the items in an array, you can loop through each item in the array using an [iteration tag]({{ "/tags/iteration" | prepend: site.baseurl }}).
|
||||
To access all the items in an array, you can loop through each item in the array using an [iteration tag]({{ "/tags/iteration/" | prepend: site.baseurl }}).
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
|
||||
{% for user in site.users %}
|
||||
{{ user }}
|
||||
@@ -95,22 +98,20 @@ To access all the items in an array, you can loop through each item in the array
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% raw %}
|
||||
Tobi Laura Tetsuro Adam
|
||||
{% endraw %}
|
||||
Tobi Laura Tetsuro Adam
|
||||
```
|
||||
|
||||
### 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. A negative index will count from the end of the array.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
|
||||
{{ site.users[0] }}
|
||||
{{ site.users[1] }}
|
||||
{{ site.users[3] }}
|
||||
{{ site.users[-1] }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -125,4 +126,32 @@ Adam
|
||||
|
||||
You cannot initialize arrays using only Liquid.
|
||||
|
||||
You can, however, use the [split]({{ "/filters/split" | prepend: site.baseurl }}) filter to break a string into an array of substrings.
|
||||
You can, however, use the [`split`]({{ "/filters/split/" | prepend: site.baseurl }}) filter to break a string into an array of substrings.
|
||||
|
||||
## EmptyDrop
|
||||
|
||||
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
|
||||
{%- raw -%}
|
||||
{% assign variable = "hello" %}
|
||||
{% assign page_1 = pages[variable] %}
|
||||
{% assign page_2 = pages["does-not-exist"] %}
|
||||
{% assign page_3 = pages.this-handle-does-not-exist %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
### Checking for emptiness
|
||||
|
||||
You can check to see if an object exists or not before you access any of its attributes.
|
||||
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% unless pages == empty %}
|
||||
<h1>{{ pages.frontpage.title }}</h1>
|
||||
<div>{{ pages.frontpage.content }}</div>
|
||||
{% endunless %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
Both empty strings and empty arrays will return `true` if checked for equivalence with `empty`.
|
||||
|
||||
@@ -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 Help Center](https://help.shopify.com/themes/liquid). 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/development-stores).
|
||||
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).
|
||||
|
||||
## Jekyll
|
||||
|
||||
@@ -19,6 +19,6 @@ Shopify's version of Liquid is documented in the [Shopify Help Center](https://h
|
||||
|
||||
Jekyll also powers [GitHub Pages](https://pages.github.com/), a web hosting service that lets you push a Jekyll installation to a GitHub repository and have the resulting website published. This website is built using GitHub Pages.
|
||||
|
||||
Jekyll might not be using the latest version of Liquid. This means that the tags and filters listed on this site may not work in Jekyll. Often the Jekyll project will wait for a stable release of Liquid rather than using a beta or release candidate version. To see what version of Liquid Jekyll is using, check the **runtime dependencies** section of [Jekyll's gem page](https://rubygems.org/gems/jekyll).
|
||||
Jekyll might not be using the latest version of Liquid. This means that the tags and filters listed on this site may not work in Jekyll. Often the Jekyll project will wait for a stable release of Liquid rather than using a beta or release candidate version. To see which version of Liquid is being used by Jekyll or GitHub Pages, check the **runtime dependencies** section of the gem page for [Jekyll](https://rubygems.org/gems/jekyll) or [GitHub Pages](https://rubygems.org/gems/github-pages).
|
||||
|
||||
Jekyll's version of Liquid is documented in the [Templates section of Jekyll's documentation](http://jekyllrb.com/docs/templates/). If you want to try out Jekyll's version of Liquid, you can clone the Jekyll project or install Jekyll as a gem and test Liquid on a static site.
|
||||
Jekyll's version of Liquid is documented in the [Liquid section of Jekyll's documentation](https://jekyllrb.com/docs/liquid/). If you want to try out Jekyll's version of Liquid, you can clone the Jekyll project or install Jekyll as a gem and test Liquid on a static site.
|
||||
|
||||
@@ -5,76 +5,82 @@ description: An overview of controlling whitespace between code in the Liquid te
|
||||
|
||||
In Liquid, you can include a hyphen in your tag syntax `{% raw %}{{-{% endraw %}`, `{% raw %}-}}{% endraw %}`, `{% raw %}{%-{% endraw %}`, and `{% raw %}-%}{% endraw %}` to strip whitespace from the left or right side of a rendered tag.
|
||||
|
||||
Normally, even if it doesn't output text, any line of Liquid in your template will still output a blank line in your rendered HTML:
|
||||
Normally, even if it doesn't print text, any line of Liquid in your template will still print a blank line in your rendered HTML:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign my_variable = "tomato" %}
|
||||
{{ my_variable }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
Notice the blank line before "tomato" in the rendered template:
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{% assign my_variable = "tomato" %}
|
||||
{{ my_variable }}
|
||||
```
|
||||
|
||||
By including hyphens in your `assign` tag, you can strip the generated whitespace from the rendered template:
|
||||
By including a hyphen in your `assign` closing delimiter, you can strip the whitespace following it from the rendered template:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
{%- assign my_variable = "tomato" -%}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign my_variable = "tomato" -%}
|
||||
{{ my_variable }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
tomato
|
||||
```text
|
||||
{% assign my_variable = "tomato" -%}
|
||||
{{ my_variable }}
|
||||
```
|
||||
|
||||
If you don't want any of your tags to output whitespace, as a general rule you can add hyphens to both sides of all your tags (`{% raw %}{%-{% endraw %}` and `{% raw %}-%}{% endraw %}`):
|
||||
If you don't want any of your tags to print whitespace, as a general rule you can add hyphens to both sides of all your tags (`{% raw %}{%-{% endraw %}` and `{% raw %}-%}{% endraw %}`):
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign username = "John G. Chalmers-Smith" %}
|
||||
{% if username and username.size > 10 %}
|
||||
Wow, {{ username }}, you have a long name!
|
||||
Wow, {{ username }} , you have a long name!
|
||||
{% else %}
|
||||
Hello there!
|
||||
{% endif %}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output without whitespace control</p>
|
||||
``` text
|
||||
```text
|
||||
{% assign username = "John G. Chalmers-Smith" %}
|
||||
{% if username and username.size > 10 %}
|
||||
Wow, {{ username }}, you have a long name!
|
||||
Wow, {{ username }} , you have a long name!
|
||||
{% else %}
|
||||
Hello there!
|
||||
{% endif %}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
{%- assign username = "John G. Chalmers-Smith" -%}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign username = "John G. Chalmers-Smith" -%}
|
||||
{%- if username and username.size > 10 -%}
|
||||
Wow, {{ username }}, you have a long name!
|
||||
Wow, {{ username -}} , you have a long name!
|
||||
{%- else -%}
|
||||
Hello there!
|
||||
{%- endif -%}
|
||||
```
|
||||
{%- endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output with whitespace control</p>
|
||||
``` text
|
||||
Wow, John G. Chalmers-Smith, you have a long name!
|
||||
```text
|
||||
{% assign username = "John G. Chalmers-Smith" -%}
|
||||
{%- if username and username.size > 10 -%}
|
||||
Wow, {{ username -}} , you have a long name!
|
||||
{%- else -%}
|
||||
Hello there!
|
||||
{%- endif %}
|
||||
```
|
||||
|
||||
@@ -15,6 +15,7 @@ exclude:
|
||||
- package-lock.json
|
||||
- node_modules
|
||||
- vendor
|
||||
- tags
|
||||
keep_files: ["css"]
|
||||
|
||||
# Collections
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: abs
|
||||
description: Liquid filter that gets the absolute value of a number.
|
||||
description: Liquid filter that returns the absolute value of a number.
|
||||
redirect_from: /filters/
|
||||
---
|
||||
|
||||
@@ -8,38 +8,28 @@ Returns the absolute value of a number.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ -17 | abs }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
17
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 4 | abs }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
4
|
||||
{{ -17 | abs }}
|
||||
{{ 4 | abs }}
|
||||
```
|
||||
|
||||
`abs` will also work on a string if the string only contains a number.
|
||||
`abs` will also work on a string that only contains a number.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "-19.86" | abs }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
19.86
|
||||
{{ "-19.86" | abs }}
|
||||
```
|
||||
|
||||
@@ -3,11 +3,11 @@ title: append
|
||||
description: Liquid filter that appends a string to another string.
|
||||
---
|
||||
|
||||
Concatenates two strings and returns the concatenated value.
|
||||
Adds the specified string to the end of another string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "/my/fancy/url" | append: ".html" }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -17,11 +17,11 @@ Concatenates two strings and returns the concatenated value.
|
||||
{{ "/my/fancy/url" | append: ".html" }}
|
||||
```
|
||||
|
||||
`append` can also be used with variables:
|
||||
`append` can also accept a variable as its argument.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign filename = "/index.html" %}
|
||||
{{ "website.com" | append: filename }}
|
||||
{% endraw %}
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
---
|
||||
title: at_least
|
||||
description: Liquid filter that limits a number to a minimum value
|
||||
description: Liquid filter that limits a number to a minimum value.
|
||||
version-badge: 4.0.1
|
||||
---
|
||||
|
||||
Limits a number to a minimum value.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ 4 | at_least: 5 }}
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```
|
||||
5
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{{ 4 | at_least: 3 }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```
|
||||
```text
|
||||
5
|
||||
4
|
||||
```
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
---
|
||||
title: at_most
|
||||
description: Liquid filter that limits a number to a maximum value
|
||||
description: Liquid filter that limits a number to a maximum value.
|
||||
version-badge: 4.0.1
|
||||
---
|
||||
|
||||
Limits a number to a maximum value.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ 4 | at_most: 5 }}
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```
|
||||
4
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{{ 4 | at_most: 3 }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```
|
||||
```text
|
||||
4
|
||||
3
|
||||
```
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
---
|
||||
title: capitalize
|
||||
description: Liquid filter that capitalizes the first character in a string.
|
||||
description: Liquid filter that capitalizes the first character of a string and downcases the remaining characters.
|
||||
---
|
||||
|
||||
Makes the first character of a string capitalized.
|
||||
Makes the first character of a string capitalized and converts the remaining characters to lowercase.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "title" | capitalize }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
Title
|
||||
{{ "title" | capitalize }}
|
||||
```
|
||||
|
||||
`capitalize` only capitalizes the first character of the string, so later words are not affected:
|
||||
Only the first character of a string is capitalized, so later words are not capitalized:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ "my great title" | capitalize }}
|
||||
{%- raw -%}
|
||||
{{ "my GREAT title" | capitalize }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
My great title
|
||||
{{ "my GREAT title" | capitalize }}
|
||||
```
|
||||
|
||||
@@ -1,43 +1,23 @@
|
||||
---
|
||||
title: ceil
|
||||
description: Liquid filter that gets the ceiling of a number by rounding up to the nearest integer.
|
||||
description: Liquid filter that returns the ceiling of a number by rounding up to the nearest integer.
|
||||
---
|
||||
|
||||
Rounds the input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
|
||||
Rounds an input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ 1.2 | ceil }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 1.2 | ceil }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 2.0 | ceil }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 2.0 | ceil }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 183.357 | ceil }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 1.2 | ceil }}
|
||||
{{ 2.0 | ceil }}
|
||||
{{ 183.357 | ceil }}
|
||||
```
|
||||
|
||||
@@ -45,7 +25,7 @@ Here the input value is a string:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "3.5" | ceil }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
---
|
||||
title: compact
|
||||
description: Liquid filter that removes nil values from an array.
|
||||
version-badge: 4.0.0
|
||||
---
|
||||
|
||||
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
|
||||
{% assign site_categories = site.pages | map: 'category' %}
|
||||
{%- raw -%}
|
||||
{% assign site_categories = site.pages | map: "category" %}
|
||||
|
||||
{% for category in site_categories %}
|
||||
{{ category }}
|
||||
- {{ category }}
|
||||
{% endfor %}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
business
|
||||
celebrities
|
||||
|
||||
lifestyle
|
||||
sports
|
||||
|
||||
technology
|
||||
- business
|
||||
- celebrities
|
||||
-
|
||||
- lifestyle
|
||||
- sports
|
||||
-
|
||||
- technology
|
||||
```
|
||||
|
||||
By using `compact` when we create our `site_categories` array, we can remove all the `nil` values in the array.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{% assign site_categories = site.pages | map: 'category' | compact %}
|
||||
{%- raw -%}
|
||||
{% assign site_categories = site.pages | map: "category" | compact %}
|
||||
|
||||
{% for category in site_categories %}
|
||||
{{ category }}
|
||||
- {{ category }}
|
||||
{% endfor %}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
business
|
||||
celebrities
|
||||
lifestyle
|
||||
sports
|
||||
technology
|
||||
- business
|
||||
- celebrities
|
||||
- lifestyle
|
||||
- sports
|
||||
- technology
|
||||
```
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
---
|
||||
title: concat
|
||||
description: Liquid filter that concatenates arrays.
|
||||
version-badge: 4.0.0
|
||||
---
|
||||
|
||||
Concatenates (joins together) multiple arrays. The resulting array contains all the items from the input arrays.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign fruits = "apples, oranges, peaches" | split: ", " %}
|
||||
{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %}
|
||||
|
||||
@@ -16,8 +17,8 @@ Concatenates (joins together) multiple arrays. The resulting array contains all
|
||||
{% for item in everything %}
|
||||
- {{ item }}
|
||||
{% endfor %}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
@@ -29,11 +30,11 @@ Concatenates (joins together) multiple arrays. The resulting array contains all
|
||||
- potatoes
|
||||
```
|
||||
|
||||
You can string together `concat` filters to join more than two arrays:
|
||||
You can string together multiple `concat` filters to join more than two arrays.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign furniture = "chairs, tables, shelves" | split: ", " %}
|
||||
|
||||
{% assign everything = fruits | concat: vegetables | concat: furniture %}
|
||||
@@ -41,8 +42,8 @@ You can string together `concat` filters to join more than two arrays:
|
||||
{% for item in everything %}
|
||||
- {{ item }}
|
||||
{% endfor %}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
|
||||
@@ -7,7 +7,7 @@ Converts a timestamp into another date format. The format for this syntax is the
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ article.published_at | date: "%a, %b %d, %y" }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -19,7 +19,7 @@ Fri, Jul 17, 15
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ article.published_at | date: "%Y" }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -29,11 +29,11 @@ Fri, Jul 17, 15
|
||||
2015
|
||||
```
|
||||
|
||||
`date` works on strings if they contain well-formatted dates:
|
||||
`date` works on strings if they contain well-formatted dates.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "March 14, 2016" | date: "%b %d, %y" }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -43,11 +43,11 @@ Fri, Jul 17, 15
|
||||
{{ "March 14, 2016" | date: "%b %d, %y" }}
|
||||
```
|
||||
|
||||
To get the current time, pass the special word `"now"` (or `"today"`) to `date`:
|
||||
To get the current time, pass the special word `"now"` (or `"today"`) to `date`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -3,27 +3,27 @@ title: default
|
||||
description: Liquid filter that specifies a fallback in case a value doesn't exist.
|
||||
---
|
||||
|
||||
Allows you to specify a fallback in case a value doesn't exist. `default` will show its value if the left side is `nil`, `false`, or empty.
|
||||
Sets a default value for any variable with no assigned value. `default` will show its value if the input is `nil`, `false`, or empty.
|
||||
|
||||
In this example, `product_price` is not defined, so the default value is used.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ product_price | default: 2.99 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
2.99
|
||||
{{ product_price | default: 2.99 }}
|
||||
```
|
||||
|
||||
In this example, `product_price` is defined, so the default value is not used.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign product_price = 4.99 %}
|
||||
{{ product_price | default: 2.99 }}
|
||||
{% endraw %}
|
||||
@@ -31,14 +31,15 @@ In this example, `product_price` is defined, so the default value is not used.
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
4.99
|
||||
{% assign product_price = 4.99 %}
|
||||
{{ product_price | default: 2.99 }}
|
||||
```
|
||||
|
||||
In this example, `product_price` is empty, so the default value is used.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign product_price = "" %}
|
||||
{{ product_price | default: 2.99 }}
|
||||
{% endraw %}
|
||||
@@ -46,5 +47,24 @@ In this example, `product_price` is empty, so the default value is used.
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
2.99
|
||||
{% assign product_price = "" %}
|
||||
{{ product_price | default: 2.99 }}
|
||||
```
|
||||
|
||||
### Allowing `false` {%- include version-badge.html version="5.0.0" %}
|
||||
|
||||
To allow variables to return `false` instead of the default value, you can use the `allow_false` parameter.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign display_price = false %}
|
||||
{{ display_price | default: true, allow_false: true }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
|
||||
false
|
||||
```
|
||||
|
||||
@@ -3,31 +3,21 @@ title: divided_by
|
||||
description: Liquid filter that divides a number by another number.
|
||||
---
|
||||
|
||||
Divides a number by the specified number.
|
||||
Divides a number by another number.
|
||||
|
||||
The result is rounded down to the nearest integer (that is, the [floor]({{ site.baseurl }}/filters/floor)) if the divisor is an integer.
|
||||
The result is rounded down to the nearest integer (that is, the [floor]({{ "/filters/floor/" | prepend: site.baseurl }})) if the divisor is an integer.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ 16 | divided_by: 4 }}
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
{{ 16 | divided_by: 4 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
{{ 5 | divided_by: 3 }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{{ 16 | divided_by: 4 }}
|
||||
{{ 5 | divided_by: 3 }}
|
||||
```
|
||||
|
||||
@@ -38,28 +28,28 @@ The result is rounded down to the nearest integer (that is, the [floor]({{ site.
|
||||
For example, here the divisor is an integer:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ 20 | divided_by: 7 }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{{ 20 | divided_by: 7 }}
|
||||
```
|
||||
|
||||
Here it is a float:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ 20 | divided_by: 7.0 }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{{ 20 | divided_by: 7.0 }}
|
||||
```
|
||||
|
||||
@@ -70,32 +60,32 @@ You might want to use a variable as a divisor, in which case you can't simply ad
|
||||
In this example, we're dividing by a variable that contains an integer, so we get an integer:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign my_integer = 7 %}
|
||||
{{ 20 | divided_by: my_integer }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{% assign my_integer = 7 %}
|
||||
{{ 20 | divided_by: my_integer }}
|
||||
```
|
||||
|
||||
Here, we [multiply]({{ site.baseurl}}/filters/times) the variable by `1.0` to get a float, then divide by the float instead:
|
||||
Here, we [multiply]({{ "/filters/times/" | prepend: site.baseurl }}) the variable by `1.0` to get a float, then divide by the float instead:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign my_integer = 7 %}
|
||||
{% assign my_float = my_integer | times: 1.0 %}
|
||||
{{ 20 | divided_by: my_float }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{% assign my_integer = 7 %}
|
||||
{% assign my_float = my_integer | times: 1.0 %}
|
||||
{{ 20 | divided_by: my_float }}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
title: downcase
|
||||
description: Liquid filter that coverts a string to lowercase.
|
||||
description: Liquid filter that converts a string to lowercase.
|
||||
---
|
||||
|
||||
Makes each character in a string lowercase. It has no effect on strings which are already all lowercase.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Parker Moore" | downcase }}
|
||||
{% 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>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "apple" | downcase }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Escapes a string by replacing characters with escape sequences (so that the stri
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Have you read 'James & the Giant Peach'?" | escape }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -19,7 +19,7 @@ Escapes a string by replacing characters with escape sequences (so that the stri
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Tetsuro Takara" | escape }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Escapes a string without changing existing escaped entities. It doesn't change s
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "1 < 2 & 3" | escape_once }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -19,7 +19,7 @@ Escapes a string without changing existing escaped entities. It doesn't change s
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "1 < 2 & 3" | escape_once }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -7,23 +7,19 @@ Returns the first item of an array.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
|
||||
|
||||
{{ my_array.first }}
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | split: " " | first }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
|
||||
|
||||
{{ my_array.first }}
|
||||
{{ "Ground control to Major Tom." | split: " " | first }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
|
||||
|
||||
{{ my_array.first }}
|
||||
@@ -37,10 +33,10 @@ Returns the first item of an array.
|
||||
{{ my_array.first }}
|
||||
```
|
||||
|
||||
You can use `first` with dot notation when you need to use the filter inside a tag.
|
||||
You can use `first` with dot notation when you need to use the filter inside a tag:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% if my_array.first == "zebra" %}
|
||||
Here comes a zebra!
|
||||
{% endif %}
|
||||
|
||||
@@ -1,43 +1,23 @@
|
||||
---
|
||||
title: floor
|
||||
description: Liquid filter that gets the floor of a number by rounding down to the nearest integer.
|
||||
description: Liquid filter that returns the floor of a number by rounding down to the nearest integer.
|
||||
---
|
||||
|
||||
Rounds a number down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
|
||||
Rounds an input down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ 1.2 | floor }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 1.2 | floor }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 2.0 | floor }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 2.0 | floor }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 183.357 | floor }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 1.2 | floor }}
|
||||
{{ 2.0 | floor }}
|
||||
{{ 183.357 | floor }}
|
||||
```
|
||||
|
||||
@@ -45,7 +25,7 @@ Here the input value is a string:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "3.5" | floor }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -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>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
|
||||
|
||||
{{ beatles | join: " and " }}
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
---
|
||||
title: last
|
||||
description: Liquid filter that gets the last value in an array.
|
||||
description: Liquid filter that returns the last item of an array.
|
||||
---
|
||||
|
||||
Returns the last item of an array.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
|
||||
|
||||
{{ my_array.last }}
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | split: " " | last }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
|
||||
|
||||
{{ my_array.last }}
|
||||
{{ "Ground control to Major Tom." | split: " " | last }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
|
||||
|
||||
{{ my_array.last }}
|
||||
@@ -37,10 +33,10 @@ Returns the last item of an array.
|
||||
{{ my_array.last }}
|
||||
```
|
||||
|
||||
You can use `last` with dot notation when you need to use the filter inside a tag.
|
||||
You can use `last` with dot notation when you need to use the filter inside a tag:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% if my_array.last == "tiger" %}
|
||||
There goes a tiger!
|
||||
{% endif %}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
---
|
||||
title: lstrip
|
||||
description: Liquid filter that removes whitespace from the left side of a string.
|
||||
description: Liquid filter that removes all whitespace from the left side of a string.
|
||||
---
|
||||
|
||||
Removes all whitespaces (tabs, spaces, and newlines) from the beginning of a string. The filter does not affect spaces between words.
|
||||
Removes all whitespace (tabs, spaces, and newlines) from the **left** side of a string. It does not affect spaces between words.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ " So much room for activities! " | lstrip }}
|
||||
{%- raw -%}
|
||||
{{ " So much room for activities " | lstrip }}!
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ " So much room for activities! " | lstrip }}
|
||||
{{ " So much room for activities " | lstrip }}!
|
||||
```
|
||||
|
||||
@@ -9,20 +9,20 @@ In this example, assume the object `site.pages` contains all the metadata for a
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign all_categories = site.pages | map: "category" %}
|
||||
|
||||
{% for item in all_categories %}
|
||||
{{ item }}
|
||||
- {{ item }}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
business
|
||||
celebrities
|
||||
lifestyle
|
||||
sports
|
||||
technology
|
||||
- business
|
||||
- celebrities
|
||||
- lifestyle
|
||||
- sports
|
||||
- technology
|
||||
```
|
||||
|
||||
@@ -1,42 +1,22 @@
|
||||
---
|
||||
title: minus
|
||||
description: Liquid filter that subtracts one number from another.
|
||||
description: Liquid filter that subtracts one number from another number.
|
||||
---
|
||||
|
||||
Subtracts a number from another number.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ 4 | minus: 2 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 4 | minus: 2 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 16 | minus: 4 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 16 | minus: 4 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 183.357 | minus: 12 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 4 | minus: 2 }}
|
||||
{{ 16 | minus: 4 }}
|
||||
{{ 183.357 | minus: 12 }}
|
||||
```
|
||||
|
||||
@@ -1,42 +1,22 @@
|
||||
---
|
||||
title: modulo
|
||||
description: Liquid filter that returns the remainder from a division operation.
|
||||
description: Liquid filter that returns the remainder of a division operation.
|
||||
---
|
||||
|
||||
Returns the remainder of a division operation.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ 3 | modulo: 2 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 3 | modulo: 2 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 24 | modulo: 7 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 24 | modulo: 7 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 183.357 | modulo: 12 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 3 | modulo: 2 }}
|
||||
{{ 24 | modulo: 7 }}
|
||||
{{ 183.357 | modulo: 12 }}
|
||||
```
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
title: newline_to_br
|
||||
description: Liquid filter that converts newlines in an input string to HTML <br> tags.
|
||||
description: Liquid filter that converts newlines in a string to HTML <br /> tags.
|
||||
---
|
||||
|
||||
Replaces every newline (`\n`) with an HTML line break (`<br>`).
|
||||
Inserts an HTML line break (`<br />`) in front of each newline (`\n`) in a string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% capture string_with_newlines %}
|
||||
Hello
|
||||
there
|
||||
|
||||
@@ -1,42 +1,22 @@
|
||||
---
|
||||
title: plus
|
||||
description: Liquid filter that adds a number to another number.
|
||||
description: Liquid filter that adds one number to another number.
|
||||
---
|
||||
|
||||
Adds a number to another number.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ 4 | plus: 2 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 4 | plus: 2 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 16 | plus: 4 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 16 | plus: 4 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 183.357 | plus: 12 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 4 | plus: 2 }}
|
||||
{{ 16 | plus: 4 }}
|
||||
{{ 183.357 | plus: 12 }}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Adds the specified string to the beginning of another string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -17,13 +17,12 @@ Adds the specified string to the beginning of another string.
|
||||
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
|
||||
```
|
||||
|
||||
You can also `prepend` variables:
|
||||
`prepend` can also accept a variable as its argument.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- 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 }}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Removes every occurrence of the specified substring from a string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "I strained to see the train through the rain" | remove: "rain" }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Removes only the first occurrence of the specified substring from a string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -3,11 +3,11 @@ title: replace
|
||||
description: Liquid filter that replaces all occurences of a given substring in a string.
|
||||
---
|
||||
|
||||
Replaces every occurrence of an argument in a string with the second argument.
|
||||
Replaces every occurrence of the first argument in a string with the second argument.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -7,14 +7,12 @@ Replaces only the first occurrence of the first argument in a string with the se
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% assign my_string = "Take my protein pills and put my helmet on" %}
|
||||
{{ my_string | replace_first: "my", "your" }}
|
||||
{%- raw -%}
|
||||
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% assign my_string = "Take my protein pills and put my helmet on" %}
|
||||
{{ my_string | replace_first: "my", "your" }}
|
||||
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Reverses the order of the items in an array. `reverse` cannot reverse a string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
|
||||
|
||||
{{ my_array | reverse | join: ", " }}
|
||||
@@ -21,11 +21,11 @@ Reverses the order of the items in an array. `reverse` cannot reverse a string.
|
||||
{{ my_array | reverse | join: ", " }}
|
||||
```
|
||||
|
||||
`reverse` cannot be used directly on a string, but you can split a string into an array, reverse the array, and rejoin it by chaining together filters:
|
||||
Although `reverse` cannot be used directly on a string, you can split a string into an array, reverse the array, and rejoin it by chaining together filters.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -3,40 +3,20 @@ title: round
|
||||
description: Liquid filter that rounds a number to the nearest integer.
|
||||
---
|
||||
|
||||
Rounds an input number to the nearest integer or, if a number is specified as an argument, to that number of decimal places.
|
||||
Rounds a number to the nearest integer or, if a number is passed as an argument, to that number of decimal places.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ 1.2 | round }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 1.2 | round }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 2.7 | round }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 2.7 | round }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 183.357 | round: 2 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 1.2 | round }}
|
||||
{{ 2.7 | round }}
|
||||
{{ 183.357 | round: 2 }}
|
||||
```
|
||||
|
||||
@@ -3,16 +3,16 @@ title: rstrip
|
||||
description: Liquid filter that removes all whitespace from the right side of a string.
|
||||
---
|
||||
|
||||
Removes all whitespace (tabs, spaces, and newlines) from the right side of a string.
|
||||
Removes all whitespace (tabs, spaces, and newlines) from the **right** side of a string. It does not affect spaces between words.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ " So much room for activities! " | rstrip }}
|
||||
{%- raw -%}
|
||||
{{ " So much room for activities " | rstrip }}!
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ " So much room for activities! " | rstrip }}
|
||||
{{ " So much room for activities " | rstrip }}!
|
||||
```
|
||||
|
||||
@@ -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>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | size }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -19,10 +19,10 @@ Returns the number of characters in a string or the number of items in an array.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
|
||||
|
||||
{{ my_array | size }}
|
||||
{{ my_array.size }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -30,13 +30,13 @@ Returns the number of characters in a string or the number of items in an array.
|
||||
```text
|
||||
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
|
||||
|
||||
{{ my_array | size }}
|
||||
{{ my_array.size }}
|
||||
```
|
||||
|
||||
You can use `size` with dot notation when you need to use the filter inside a tag.
|
||||
You can use `size` with dot notation when you need to use the filter inside a tag:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% if site.pages.size > 10 %}
|
||||
This is a big website!
|
||||
{% endif %}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
---
|
||||
title: slice
|
||||
description: Liquid filter that returns a substring from a given position in a string.
|
||||
description: Liquid filter that returns a substring or item from a given position in a string or array.
|
||||
---
|
||||
|
||||
Returns a substring of 1 character beginning at the index specified by the argument passed in. An optional second argument specifies the length of the substring to be returned.
|
||||
Returns a substring of one character or series of array items beginning at the index specified by the first argument. An optional second argument specifies the length of the substring or number of array items to be returned.
|
||||
|
||||
String indices are numbered starting from 0.
|
||||
String or array indices are numbered starting from 0.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Liquid" | slice: 0 }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -21,7 +21,7 @@ String indices are numbered starting from 0.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Liquid" | slice: 2 }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -33,7 +33,7 @@ String indices are numbered starting from 0.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Liquid" | slice: 2, 5 }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -43,11 +43,27 @@ String indices are numbered starting from 0.
|
||||
{{ "Liquid" | slice: 2, 5 }}
|
||||
```
|
||||
|
||||
If the first parameter is a negative number, the indices are counted from the end of the string:
|
||||
Here the input value is an array:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
|
||||
{{ beatles | slice: 1, 2 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
|
||||
{{ beatles | slice: 1, 2 }}
|
||||
```
|
||||
|
||||
If the first argument is a negative number, the indices are counted from the end of the string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ "Liquid" | slice: -3, 2 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Sorts items in an array in case-sensitive order.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
|
||||
|
||||
{{ my_array | sort | join: ", " }}
|
||||
@@ -21,10 +21,10 @@ Sorts items in an array in case-sensitive order.
|
||||
{{ my_array | sort | join: ", " }}
|
||||
```
|
||||
|
||||
An optional parameter specifies which property of the array's items to use for sorting.
|
||||
An optional argument specifies which property of the array's items to use for sorting.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign products_by_price = collection.products | sort: "price" %}
|
||||
{% for product in products_by_price %}
|
||||
<h4>{{ product.title }}</h4>
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
---
|
||||
title: sort_natural
|
||||
description: Liquid filter that sorts an array in case-insensitive order.
|
||||
version-badge: 4.0.0
|
||||
---
|
||||
|
||||
Sorts items in an array in case-insensitive order.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
|
||||
|
||||
{{ my_array | sort_natural | join: ", " }}
|
||||
@@ -21,10 +22,10 @@ Sorts items in an array in case-insensitive order.
|
||||
{{ my_array | sort_natural | join: ", " }}
|
||||
```
|
||||
|
||||
An optional parameter specifies which property of the array's items to use for sorting.
|
||||
An optional argument specifies which property of the array's items to use for sorting.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign products_by_company = collection.products | sort_natural: "company" %}
|
||||
{% for product in products_by_company %}
|
||||
<h4>{{ product.title }}</h4>
|
||||
|
||||
@@ -3,11 +3,11 @@ title: split
|
||||
description: Liquid filter that splits a string into an array using separators.
|
||||
---
|
||||
|
||||
Divides an input string into an array using the argument as a separator. `split` is commonly used to convert comma-separated items from a string to an array.
|
||||
Divides a string into an array using the argument as a separator. `split` is commonly used to convert comma-separated items from a string to an array.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
|
||||
|
||||
{% for member in beatles %}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
---
|
||||
title: strip
|
||||
description: Liquid filter that removes whitespace from the left and right sides of a string.
|
||||
description: Liquid filter that removes all whitespace from the left and right sides of a string.
|
||||
---
|
||||
|
||||
Removes all whitespace (tabs, spaces, and newlines) from both the left and right side of a string. It does not affect spaces between words.
|
||||
Removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ " So much room for activities! " | strip }}
|
||||
{%- raw -%}
|
||||
{{ " So much room for activities " | strip }}!
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ " So much room for activities! " | strip }}
|
||||
{{ " So much room for activities " | strip }}!
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Removes any HTML tags from a string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Removes any newline characters (line breaks) from a string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% capture string_with_newlines %}
|
||||
Hello
|
||||
there
|
||||
|
||||
@@ -7,36 +7,16 @@ Multiplies a number by another number.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ 3 | times: 2 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 3 | times: 2 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 24 | times: 7 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 24 | times: 7 }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{{ 183.357 | times: 12 }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{{ 3 | times: 2 }}
|
||||
{{ 24 | times: 7 }}
|
||||
{{ 183.357 | times: 12 }}
|
||||
```
|
||||
|
||||
@@ -3,11 +3,11 @@ title: truncate
|
||||
description: Liquid filter that truncates a string to a given number of characters.
|
||||
---
|
||||
|
||||
`truncate` shortens a string down to the number of characters passed as a parameter. If the number of characters specified is less than the length of the string, an ellipsis (...) is appended to the string and is included in the character count.
|
||||
Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (...) is appended to the string and is included in the character count.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | truncate: 20 }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -19,34 +19,34 @@ description: Liquid filter that truncates a string to a given number of characte
|
||||
|
||||
### Custom ellipsis
|
||||
|
||||
`truncate` takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.
|
||||
`truncate` takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.
|
||||
|
||||
The length of the second parameter counts against the number of characters specified by the first parameter. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use **13** for the first parameter of `truncate`, since the ellipsis counts as 3 characters.
|
||||
The length of the second argument counts against the number of characters specified by the first argument. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use **13** for the first argument of `truncate`, since the ellipsis counts as 3 characters.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
|
||||
```
|
||||
|
||||
### No ellipsis
|
||||
|
||||
You can truncate to the exact number of characters specified by the first parameter and show no trailing characters by passing a blank string as the second parameter:
|
||||
You can truncate to the exact number of characters specified by the first argument and avoid showing trailing characters by passing a blank string as the second argument.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | truncate: 20, "" }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{{ "Ground control to Major Tom." | truncate: 20, "" }}
|
||||
```
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
title: truncatewords
|
||||
description: Liquid filter that truncates a string to the given number of words.
|
||||
description: Liquid filter that truncates a string to a given number of words.
|
||||
---
|
||||
|
||||
Shortens a string down to the number of words passed as the argument. If the specified number of words is less than the number of words in the string, an ellipsis (...) is appended to the string.
|
||||
Shortens a string down to the number of words passed as an argument. If the specified number of words is less than the number of words in the string, an ellipsis (...) is appended to the string.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | truncatewords: 3 }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -19,32 +19,32 @@ Shortens a string down to the number of words passed as the argument. If the spe
|
||||
|
||||
### Custom ellipsis
|
||||
|
||||
`truncatewords` takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.
|
||||
`truncatewords` takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
|
||||
```
|
||||
|
||||
### No ellipsis
|
||||
|
||||
You can avoid showing trailing characters by passing a blank string as the second parameter:
|
||||
You can avoid showing trailing characters by passing a blank string as the second argument.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
``` liquid
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
``` text
|
||||
```text
|
||||
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
|
||||
```
|
||||
|
||||
@@ -3,11 +3,11 @@ title: uniq
|
||||
description: Liquid filter that removes duplicate items from an array.
|
||||
---
|
||||
|
||||
Removes any duplicate elements in an array.
|
||||
Removes any duplicate items in an array.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
|
||||
|
||||
{{ my_array | uniq | join: ", " }}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
title: upcase
|
||||
description: Liquid filter that capitalizes every character in a string.
|
||||
description: Liquid filter that converts a string to uppercase.
|
||||
---
|
||||
|
||||
Makes each character in a string uppercase. It has no effect on strings which are already all uppercase.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Parker Moore" | upcase }}
|
||||
{% 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>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "APPLE" | upcase }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
---
|
||||
title: url_decode
|
||||
description: Liquid filter that decodes percent-encoded characters in a string.
|
||||
version-badge: 4.0.0
|
||||
---
|
||||
|
||||
Decodes a string that has been encoded as a URL or by [`url_encode`]({{ '/filters/url_encode' | prepend: site.baseurl }}).
|
||||
Decodes a string that has been encoded as a URL or by [`url_encode`]({{ "/filters/url_encode/" | prepend: site.baseurl }}).
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "%27Stop%21%27+said+Fred" | url_decode }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
'Stop!' said Fred
|
||||
{{ "%27Stop%21%27+said+Fred" | url_decode }}
|
||||
```
|
||||
|
||||
@@ -7,7 +7,7 @@ Converts any URL-unsafe characters in a string into percent-encoded characters.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "john@liquid.com" | url_encode }}
|
||||
{% endraw %}
|
||||
```
|
||||
@@ -17,9 +17,11 @@ Converts any URL-unsafe characters in a string into percent-encoded characters.
|
||||
{{ "john@liquid.com" | url_encode }}
|
||||
```
|
||||
|
||||
Note that `url_encode` will turn a space into a `+` sign instead of a percent-encoded character.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{{ "Tetsuro Takara" | url_encode }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
---
|
||||
title: where
|
||||
description: Liquid filter that selects from arrays.
|
||||
version-badge: 4.0.2
|
||||
---
|
||||
|
||||
Creates an array including only the objects with a given property value, or any [truthy]({{ "/basics/truthy-and-falsy#truthy" | prepend: site.baseurl }}) value by default.
|
||||
Creates an array including only the objects with a given property value, or any [truthy]({{ "/basics/truthy-and-falsy/#truthy" | prepend: site.baseurl }}) value by default.
|
||||
|
||||
In this example, assume you have a list of products and you want to show your kitchen products separately. Using `where`, you can create an array containing only the products that have a `"type"` of `"kitchen"`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
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 %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
@@ -35,31 +36,28 @@ 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.
|
||||
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.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
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,20 +67,18 @@ 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>
|
||||
{% raw %}
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign new_shirt = products | where: "type", "shirt" | first %}
|
||||
|
||||
Featured product: {{ new_shirt.title }}
|
||||
```
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<nav class="sidebar__nav">
|
||||
<div class="sidebar__nav-interior">
|
||||
{%- for section in sections -%}
|
||||
<h3 class="section__header" id="{{ section }}">{{ section | capitalize }}</h3>
|
||||
<h3 class="section__header" id="{{ section }}-section">{{ section | capitalize }}</h3>
|
||||
|
||||
<ul class="section__links">
|
||||
{%- for item in site[section] -%}
|
||||
@@ -30,4 +30,4 @@
|
||||
</script>
|
||||
{%- endif -%}
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
1
_includes/version-badge.html
Normal file
1
_includes/version-badge.html
Normal file
@@ -0,0 +1 @@
|
||||
<span class="version-badge" title="This feature is available since version {{ include.version }}" data-version="{{ include.version }}"></span>
|
||||
@@ -55,7 +55,12 @@
|
||||
<span aria-hidden="true">{% include icons/three-bars.svg %}</span>
|
||||
<span>Menu</span>
|
||||
</button>
|
||||
{% if page.title %}<h1>{{ page.title }}</h1>{% endif %}
|
||||
{% if page.title -%}
|
||||
<h1>{{ page.title }}
|
||||
{%- if page.version-badge -%}
|
||||
{%- include version-badge.html version=page.version-badge -%}
|
||||
{%- endif -%}</h1>
|
||||
{%- endif %}
|
||||
{{ content }}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -20,3 +20,18 @@
|
||||
border-top: none;
|
||||
border-radius: 0 0 3px 3px;
|
||||
}
|
||||
|
||||
.version-badge {
|
||||
padding: 4px;
|
||||
margin-left: 10px;
|
||||
font-size: 12px;
|
||||
font-weight: 300;
|
||||
background: lighten($color-blue-1, 1);
|
||||
border: 1px solid $color-blue-2;
|
||||
border-radius: 3px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.version-badge:before {
|
||||
content: attr(data-version);
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
---
|
||||
title: Comment
|
||||
description: An overview of comments tags in the Liquid template language.
|
||||
---
|
||||
|
||||
Allows you to leave un-rendered code inside a Liquid template. Any text within
|
||||
the opening and closing `comment` blocks will not be output, and any Liquid code
|
||||
within will not be executed.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
Anything you put between {% comment %} and {% endcomment %} tags
|
||||
is turned into a comment.
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```liquid
|
||||
Anything you put between {% comment %} and {% endcomment %} tags
|
||||
is turned into a comment.
|
||||
```
|
||||
@@ -4,7 +4,7 @@ description: An overview of control flow and conditional tags in the Liquid temp
|
||||
redirect_from: /tags/
|
||||
---
|
||||
|
||||
Control flow tags can change the information Liquid shows using programming logic.
|
||||
Control flow tags create conditions that decide whether blocks of Liquid code get executed.
|
||||
|
||||
## if
|
||||
|
||||
@@ -12,8 +12,8 @@ Executes a block of code only if a certain condition is `true`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% if product.title == 'Awesome Shoes' %}
|
||||
{%- raw -%}
|
||||
{% if product.title == "Awesome Shoes" %}
|
||||
These shoes are awesome!
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
@@ -30,8 +30,8 @@ The opposite of `if` – executes a block of code only if a certain condition is
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% unless product.title == 'Awesome Shoes' %}
|
||||
{%- raw -%}
|
||||
{% unless product.title == "Awesome Shoes" %}
|
||||
These shoes are not awesome.
|
||||
{% endunless %}
|
||||
{% endraw %}
|
||||
@@ -45,8 +45,8 @@ These shoes are not awesome.
|
||||
This would be the equivalent of doing the following:
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% if product.title != 'Awesome Shoes' %}
|
||||
{%- raw -%}
|
||||
{% if product.title != "Awesome Shoes" %}
|
||||
These shoes are not awesome.
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
@@ -58,11 +58,11 @@ Adds more conditions within an `if` or `unless` block.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
<!-- If customer.name = 'anonymous' -->
|
||||
{% if customer.name == 'kevin' %}
|
||||
{%- raw -%}
|
||||
<!-- If customer.name = "anonymous" -->
|
||||
{% if customer.name == "kevin" %}
|
||||
Hey Kevin!
|
||||
{% elsif customer.name == 'anonymous' %}
|
||||
{% elsif customer.name == "anonymous" %}
|
||||
Hey Anonymous!
|
||||
{% else %}
|
||||
Hi Stranger!
|
||||
@@ -77,16 +77,18 @@ Hey Anonymous!
|
||||
|
||||
## case/when
|
||||
|
||||
Creates a switch statement to compare a variable with different values. `case` initializes the switch statement, and `when` compares its values.
|
||||
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.
|
||||
|
||||
An optional `else` statement at the end of the case provides code to execute if none of the conditions are met.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% assign handle = 'cake' %}
|
||||
{%- raw -%}
|
||||
{% assign handle = "cake" %}
|
||||
{% case handle %}
|
||||
{% when 'cake' %}
|
||||
{% when "cake" %}
|
||||
This is a cake
|
||||
{% when 'cookie' %}
|
||||
{% when "cookie", "biscuit" %}
|
||||
This is a cookie
|
||||
{% else %}
|
||||
This is not a cake nor a cookie
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
---
|
||||
title: Iteration
|
||||
description: An overview of iteration or 'loop' tags in the Liquid template language.
|
||||
description: An overview of iteration or "loop" tags in the Liquid template language.
|
||||
---
|
||||
|
||||
Iteration tags run blocks of code repeatedly.
|
||||
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://docs.shopify.com/themes/liquid/objects/for-loops).
|
||||
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).
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% for product in collection.products %}
|
||||
{{ product.title }}
|
||||
{% endfor %}
|
||||
{%- raw -%}
|
||||
{% for product in collection.products %}
|
||||
{{ product.title }}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -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>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% for product in collection.products %}
|
||||
{{ product.title }}
|
||||
{% else %}
|
||||
@@ -49,7 +49,7 @@ Causes the loop to stop iterating when it encounters the `break` tag.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% for i in (1..5) %}
|
||||
{% if i == 4 %}
|
||||
{% break %}
|
||||
@@ -71,7 +71,7 @@ Causes the loop to skip the current iteration when it encounters the `continue`
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% for i in (1..5) %}
|
||||
{% if i == 4 %}
|
||||
{% continue %}
|
||||
@@ -95,11 +95,11 @@ Limits the loop to the specified number of iterations.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
<!-- if array = [1,2,3,4,5,6] -->
|
||||
{% for item in array limit:2 %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -114,11 +114,11 @@ Begins the loop at the specified index.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
<!-- if array = [1,2,3,4,5,6] -->
|
||||
{% for item in array offset:2 %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -127,21 +127,43 @@ Begins the loop at the specified index.
|
||||
3 4 5 6
|
||||
```
|
||||
|
||||
### range
|
||||
|
||||
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.
|
||||
To start a loop from where the last loop using the same iterator left off, pass the special word `continue`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% for i in (3..5) %}
|
||||
{%- raw -%}
|
||||
<!-- if array = [1,2,3,4,5,6] -->
|
||||
{% for item in array limit: 3 %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{% for item in array limit: 3 offset: continue %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
1 2 3
|
||||
4 5 6
|
||||
```
|
||||
|
||||
### range
|
||||
|
||||
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers, and can be pulled from a variable.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% for i in (3..5) %}
|
||||
{{ i }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
{% assign num = 4 %}
|
||||
{% for i in (1..num) %}
|
||||
{% assign range = (1..num) %}
|
||||
{% for i in range %}
|
||||
{{ i }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -153,15 +175,15 @@ Defines a range of numbers to loop through. The range can be defined by both lit
|
||||
|
||||
### reversed
|
||||
|
||||
Reverses the order of the loop. Note that the flag’s spelling is different to the filter `reverse`.
|
||||
Reverses the order of the loop. Note that this flag's spelling is different from the filter `reverse`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
<!-- if array = [1,2,3,4,5,6] -->
|
||||
{% for item in array reversed %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -172,44 +194,62 @@ Reverses the order of the loop. Note that the flag’s spelling is different to
|
||||
|
||||
## cycle
|
||||
|
||||
Loops through a group of strings and outputs them in the order that they were passed as parameters. Each time `cycle` is called, the next string that was passed as a parameter is output.
|
||||
Loops through a group of strings and prints them in the order that they were passed as arguments. Each time `cycle` is called, the next string argument is printed.
|
||||
|
||||
`cycle` must be used within a [for](#for) loop block.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% cycle 'one', 'two', 'three' %}
|
||||
{% cycle 'one', 'two', 'three' %}
|
||||
{% cycle 'one', 'two', 'three' %}
|
||||
{% cycle 'one', 'two', 'three' %}
|
||||
{%- raw -%}
|
||||
{% cycle "one", "two", "three" %}
|
||||
{% cycle "one", "two", "three" %}
|
||||
{% cycle "one", "two", "three" %}
|
||||
{% cycle "one", "two", "three" %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
one
|
||||
two
|
||||
three
|
||||
one
|
||||
{% cycle "one", "two", "three" %}
|
||||
{% cycle "one", "two", "three" %}
|
||||
{% cycle "one", "two", "three" %}
|
||||
{% cycle "one", "two", "three" %}
|
||||
```
|
||||
|
||||
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)
|
||||
|
||||
`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
|
||||
|
||||
Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` HTML tags.
|
||||
`cycle` accepts a "cycle group" parameter in cases where you need multiple `cycle` blocks in one template. If no name is supplied for the cycle group, then it is assumed that multiple calls with the same parameters are one group.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% cycle "first": "one", "two", "three" %}
|
||||
{% cycle "second": "one", "two", "three" %}
|
||||
{% cycle "second": "one", "two", "three" %}
|
||||
{% cycle "first": "one", "two", "three" %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% cycle "first": "one", "two", "three" %}
|
||||
{% cycle "second": "one", "two", "three" %}
|
||||
{% cycle "second": "one", "two", "three" %}
|
||||
{% cycle "first": "one", "two", "three" %}
|
||||
```
|
||||
|
||||
## tablerow
|
||||
|
||||
Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` 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).
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
<table>
|
||||
{% tablerow product in collection.products %}
|
||||
{{ product.title }}
|
||||
@@ -252,7 +292,7 @@ Defines how many columns the tables should have.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% tablerow product in collection.products cols:2 %}
|
||||
{{ product.title }}
|
||||
{% endtablerow %}
|
||||
@@ -291,10 +331,10 @@ Defines how many columns the tables should have.
|
||||
|
||||
#### limit
|
||||
|
||||
Exits the tablerow after a specific index.
|
||||
Exits the `tablerow` loop after a specific index.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% tablerow product in collection.products cols:2 limit:3 %}
|
||||
{{ product.title }}
|
||||
{% endtablerow %}
|
||||
@@ -303,10 +343,10 @@ Exits the tablerow after a specific index.
|
||||
|
||||
### offset
|
||||
|
||||
Starts the tablerow after a specific index.
|
||||
Starts the `tablerow` loop after a specific index.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% tablerow product in collection.products cols:2 offset:3 %}
|
||||
{{ product.title }}
|
||||
{% endtablerow %}
|
||||
@@ -318,22 +358,22 @@ Starts the tablerow after a specific index.
|
||||
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.
|
||||
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
<!--variable number example-->
|
||||
|
||||
{% assign num = 4 %}
|
||||
<table>
|
||||
{% tablerow i in (1..num) %}
|
||||
{% tablerow i in (1..num) %}
|
||||
{{ i }}
|
||||
{% endtablerow %}
|
||||
{% endtablerow %}
|
||||
</table>
|
||||
|
||||
<!--literal number example-->
|
||||
|
||||
<table>
|
||||
{% tablerow i in (3..5) %}
|
||||
{% tablerow i in (3..5) %}
|
||||
{{ i }}
|
||||
{% endtablerow %}
|
||||
{% endtablerow %}
|
||||
</table>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
22
_tags/raw.md
22
_tags/raw.md
@@ -1,22 +0,0 @@
|
||||
---
|
||||
title: Raw
|
||||
description: An overview of raw tags in the Liquid template language.
|
||||
---
|
||||
|
||||
Raw temporarily disables tag processing. This is useful for generating content
|
||||
(eg, Mustache, Handlebars) which uses conflicting syntax.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
<pre class="highlight">
|
||||
<code>{% raw %}
|
||||
{% raw %}
|
||||
In Handlebars, {{ this }} will be HTML-escaped, but
|
||||
{{{ that }}} will not.
|
||||
{% endraw %}
|
||||
{% endraw %}</code>
|
||||
</pre>
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% raw %}In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not.{% endraw %}
|
||||
```
|
||||
172
_tags/template.md
Normal file
172
_tags/template.md
Normal file
@@ -0,0 +1,172 @@
|
||||
---
|
||||
title: Template
|
||||
description: An overview of template tags in the Liquid template language.
|
||||
redirect_from:
|
||||
- /tags/comment/
|
||||
- /tags/raw/
|
||||
---
|
||||
|
||||
Template tags tell Liquid where to disable processing for comments or non-Liquid markup, and how to establish relations among template files.
|
||||
|
||||
## comment
|
||||
|
||||
Allows you to leave un-rendered code inside a Liquid template. Any text within the opening and closing `comment` blocks will not be printed, and any Liquid code within will not be executed.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign verb = "turned" %}
|
||||
{% comment %}
|
||||
{% assign verb = "converted" %}
|
||||
{% endcomment %}
|
||||
Anything you put between {% comment %} and {% endcomment %} tags
|
||||
is {{ verb }} into a comment.
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```liquid
|
||||
{% assign verb = "turned" %}
|
||||
{% comment %}
|
||||
{% assign verb = "converted" %}
|
||||
{% endcomment %}
|
||||
Anything you put between {% comment %} and {% endcomment %} tags
|
||||
is {{ verb }} into a comment.
|
||||
```
|
||||
|
||||
## 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/).
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{{ "%7B%25+raw+%25%7D" | url_decode }}{% raw %}
|
||||
In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not.
|
||||
{% endraw %}{{ "%7B%25+endraw+%25%7D" | url_decode }}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
{% raw %}
|
||||
In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not.
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
## liquid {%- include version-badge.html version="5.0.0" %}
|
||||
|
||||
Encloses multiple tags within one set of delimiters, to allow writing Liquid logic more concisely.
|
||||
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% liquid
|
||||
case section.blocks.size
|
||||
when 1
|
||||
assign column_size = ''
|
||||
when 2
|
||||
assign column_size = 'one-half'
|
||||
when 3
|
||||
assign column_size = 'one-third'
|
||||
else
|
||||
assign column_size = 'one-quarter'
|
||||
endcase %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
Because any tag blocks opened within a `liquid` tag must also be closed within the same tag, use [`echo`](#echo) to output data.
|
||||
|
||||
## echo {%- include version-badge.html version="5.0.0" %}
|
||||
|
||||
Outputs an expression in the rendered HTML. This is identical to wrapping an expression in `{% raw %}{{{% endraw %}` and `{% raw %}}}{% endraw %}`, but works inside [`liquid`](#liquid) tags and supports [filters]({{ "/basics/introduction/#filters" | prepend: site.baseurl }}).
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% liquid
|
||||
for product in collection.products
|
||||
echo product.title | capitalize
|
||||
endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
Hat Shirt Pants
|
||||
```
|
||||
|
||||
## render {%- include version-badge.html version="5.0.0" %}
|
||||
|
||||
Insert the rendered content of another template within the current template.
|
||||
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% render "template-name" %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
Note that you don't need to write the file's `.liquid` extension.
|
||||
|
||||
The code within the rendered template does **not** automatically have access to the variables assigned using [variable tags]({{ "/tags/variable/" | prepend: site.baseurl }}) within the parent template. Similarly, variables assigned within the rendered template cannot be accessed by code in any other template.
|
||||
|
||||
## render (parameters)
|
||||
|
||||
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
|
||||
{%- raw -%}
|
||||
{% assign my_variable = "apples" %}
|
||||
{% render "name", my_variable: my_variable, my_other_variable: "oranges" %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
One or more objects can be passed to a template.
|
||||
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign featured_product = all_products["product_handle"] %}
|
||||
{% render "product", product: featured_product %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
### with
|
||||
|
||||
A single object can be passed to a template by using the `with` and optional `as` parameters.
|
||||
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign featured_product = all_products["product_handle"] %}
|
||||
{% render "product" with featured_product as product %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
In the example above, the `product` variable in the rendered template will hold the value of `featured_product` from the parent template.
|
||||
|
||||
### for
|
||||
|
||||
A template can be rendered once for each value of an enumerable object by using the `for` and optional `as` parameters.
|
||||
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% assign variants = product.variants %}
|
||||
{% render "product_variant" for variants as variant %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
## include
|
||||
|
||||
_The `include` tag is deprecated; please use [`render`](#render) instead._
|
||||
|
||||
Insert the rendered content of another template within the current template.
|
||||
|
||||
```liquid
|
||||
{%- raw -%}
|
||||
{% include "template-name" %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
The `include` tag works similarly to the [`render`](#render) tag, but it allows the code inside of the rendered template to access and overwrite the variables within its parent template. It has been deprecated because the way that it handles variables reduces performance and makes Liquid code harder to both read and maintain.
|
||||
|
||||
Note that when a template is rendered using the [`render`](#render) tag, the `include` tag cannot be used within the template.
|
||||
@@ -7,11 +7,11 @@ Variable tags create new Liquid variables.
|
||||
|
||||
## assign
|
||||
|
||||
Creates a new variable.
|
||||
Creates a new named variable.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign my_variable = false %}
|
||||
{% if my_variable != true %}
|
||||
This statement is valid.
|
||||
@@ -21,14 +21,14 @@ 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.
|
||||
Wrap a value in quotations `"` to save it as a string variable.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign foo = "bar" %}
|
||||
{{ foo }}
|
||||
{% endraw %}
|
||||
@@ -36,16 +36,17 @@ Wrap a variable in quotations `"` to save it as a string.
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
bar
|
||||
{% assign foo = "bar" %}
|
||||
{{ foo }}
|
||||
```
|
||||
|
||||
## capture
|
||||
|
||||
Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created through `{% raw %}{% capture %}{% endraw %}` are strings.
|
||||
Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created using `capture` are stored as strings.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% capture my_variable %}I am being captured.{% endcapture %}
|
||||
{{ my_variable }}
|
||||
{% endraw %}
|
||||
@@ -55,12 +56,13 @@ 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>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{% assign favorite_food = 'pizza' %}
|
||||
{%- raw -%}
|
||||
{% assign favorite_food = "pizza" %}
|
||||
{% assign age = 35 %}
|
||||
|
||||
{% capture about_me %}
|
||||
@@ -78,11 +80,11 @@ I am 35 and my favourite food is pizza.
|
||||
|
||||
## increment
|
||||
|
||||
Creates a new number variable, and increases its value by one every time it is called. The initial value is 0.
|
||||
Creates and outputs a new number variable with initial value `0`. On subsequent calls, it increases its value by one and outputs the new value.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% increment my_counter %}
|
||||
{% increment my_counter %}
|
||||
{% increment my_counter %}
|
||||
@@ -91,18 +93,18 @@ Creates a new number variable, and increases its value by one every time it is c
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
0
|
||||
1
|
||||
2
|
||||
{% increment my_counter %}
|
||||
{% increment my_counter %}
|
||||
{% increment my_counter %}
|
||||
```
|
||||
|
||||
Variables created through the `increment` tag are independent from variables created through `assign` or `capture`.
|
||||
Variables created using `increment` are independent from variables created using `assign` or `capture`.
|
||||
|
||||
In the example below, a variable named "var" is created through `assign`. The `increment` tag is then used several times on a variable with the same name. Note that the `increment` tag does not affect the value of "var" that was created through `assign`.
|
||||
In the example below, a variable named "var" is created using `assign`. The `increment` tag is then used several times on a variable with the same name. Note that the `increment` tag does not affect the value of "var" that was created using `assign`.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% assign var = 10 %}
|
||||
{% increment var %}
|
||||
{% increment var %}
|
||||
@@ -113,19 +115,20 @@ In the example below, a variable named "var" is created through `assign`. The `i
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
0
|
||||
1
|
||||
2
|
||||
10
|
||||
{% assign var = 10 %}
|
||||
{% increment var %}
|
||||
{% increment var %}
|
||||
{% increment var %}
|
||||
{{ var }}
|
||||
```
|
||||
|
||||
## decrement
|
||||
|
||||
Creates a new number variable, and decreases its value by one every time it is called. The initial value is -1.
|
||||
Creates and outputs a new number variable with initial value `-1`. On subsequent calls, it decreases its value by one and outputs the new value.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- raw -%}
|
||||
{% decrement variable %}
|
||||
{% decrement variable %}
|
||||
{% decrement variable %}
|
||||
@@ -134,9 +137,9 @@ Creates a new number variable, and decreases its value by one every time it is c
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
-1
|
||||
-2
|
||||
-3
|
||||
{% decrement variable %}
|
||||
{% decrement variable %}
|
||||
{% decrement variable %}
|
||||
```
|
||||
|
||||
Like [increment](#increment), variables declared inside `decrement` are independent from variables created through `assign` or `capture`.
|
||||
Like [increment](#increment), variables declared using `decrement` are independent from variables created using `assign` or `capture`.
|
||||
|
||||
Reference in New Issue
Block a user