mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 19:30:47 -07:00
@@ -1,6 +1,7 @@
|
|||||||
_site/
|
_site/
|
||||||
.sass-cache/
|
.sass-cache/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
Gemfile.lock
|
||||||
|
|
||||||
# Compiled source #
|
# Compiled source #
|
||||||
###################
|
###################
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ repository: https://github.com/Shopify/liquid
|
|||||||
|
|
||||||
# Build settings
|
# Build settings
|
||||||
baseurl: /liquid # the subpath of your site, e.g. /blog/
|
baseurl: /liquid # the subpath of your site, e.g. /blog/
|
||||||
url: http://liquidmarkup.org # the base hostname & protocol for your site
|
url: https://shopify.github.io # the base hostname & protocol for your site
|
||||||
markdown: redcarpet
|
markdown: redcarpet
|
||||||
redcarpet:
|
redcarpet:
|
||||||
extensions: ["with_toc_data", "tables", "disable_indented_code_blocks", "no_intra_emphasis"]
|
extensions: ["with_toc_data", "tables", "disable_indented_code_blocks", "no_intra_emphasis"]
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
<div class="home-users-grid">
|
<div class="home-users-grid">
|
||||||
<div class="home-users-grid__item">
|
<div class="home-users-grid__item">
|
||||||
<a href="http://jekyllrb.com/" target="_blank">
|
<a href="http://jekyllrb.com" target="_blank">
|
||||||
<img src="{{ "/images/jekyll-logo.png" | prepend: site.baseurl }}" />
|
<img src="{{ '/images/jekyll-logo.png' | prepend: site.baseurl }}" alt="Jekyll logo" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="home-users-grid__item">
|
<div class="home-users-grid__item">
|
||||||
<a href="http://www.desk.com/" target="_blank">
|
<a href="http://www.desk.com" target="_blank">
|
||||||
<img src="{{ "/images/salesforcedesk-logo.png" | prepend: site.baseurl }}" />
|
<img src="{{ '/images/salesforcedesk-logo.png' | prepend: site.baseurl }}" alt="Desk logo" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="home-users-grid__item">
|
<div class="home-users-grid__item">
|
||||||
<a href="https://www.zendesk.com/ " target="_blank">
|
<a href="//www.zendesk.com" target="_blank">
|
||||||
<img src="{{ "/images/zendesk-logo.png" | prepend: site.baseurl }}" />
|
<img src="{{ '/images/zendesk-logo.png' | prepend: site.baseurl }}" alt="ZenDesk logo" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="home-users-grid__item">
|
<div class="home-users-grid__item">
|
||||||
<a href="http://500px.com/" target="_blank">
|
<a href="//500px.com" target="_blank">
|
||||||
<img src="{{ "/images/500px-logo.png" | prepend: site.baseurl }}" />
|
<img src="{{ '/images/500px-logo.png' | prepend: site.baseurl }}" alt="500px logo" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
<meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">
|
<meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">
|
||||||
|
|
||||||
<link rel="stylesheet" href="{{ '/css/main.css' | prepend: site.baseurl }}">
|
<link rel="stylesheet" href="{{ '/css/main.css' | prepend: site.baseurl }}">
|
||||||
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
|
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
|
||||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
|
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||||
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
|
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
|
||||||
<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}" />
|
<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}" />
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
---
|
|
||||||
title: Handles
|
|
||||||
---
|
|
||||||
|
|
||||||
A handle is used to access the attributes of a Liquid object. By default, the handle is the object's title in lowercase with any spaces and special characters replaced by hyphens (-).
|
|
||||||
|
|
||||||
For example, a page with the title "About Us" can be accessed in Liquid via its handle `about-us` as shown below:
|
|
||||||
|
|
||||||
{% highlight liquid %}
|
|
||||||
{% raw %}
|
|
||||||
<!-- the content of the About Us page -->
|
|
||||||
{{ pages.about-us.content }}
|
|
||||||
{% endraw %}
|
|
||||||
{% endhighlight %}
|
|
||||||
|
|
||||||
## Creating handles
|
|
||||||
|
|
||||||
An object with the title "Shirt" will automatically be given the handle `shirt`. If there is already an object with the handle `shirt`, the handle will auto-increment. In other words, "Shirt" objects created after the first one will receive the handle `shirt-1`, `shirt-2`, and so on.
|
|
||||||
|
|
||||||
Whitespace in titles is replaced by hyphens in handles. For example, the title "My Shiny New Title" will be given the handle `my-shiny-new-title`.
|
|
||||||
|
|
||||||
Handles also determine the URL of their corresponding objects. For example, a page with the handle `about-us` would have the url `/pages/about-us`.
|
|
||||||
|
|
||||||
Websites often rely on static handles for pages, posts, or objects. To preserve design elements and avoid broken links, if you modify the title of an object, **its handle is not automatically updated**. For example, if you were to change a page title from "About Us" to "About This Website", its handle would still be `about-us`.
|
|
||||||
|
|
||||||
You can change an object's handle manually (TK how to change a handle manually)
|
|
||||||
|
|
||||||
## Accessing handle attributes
|
|
||||||
|
|
||||||
In many cases you may know the handle of a object whose attributes you want to access. You can access its attributes by pluralizing the name of the object, then using either the square bracket ( [ ] ) or dot ( . ) notation.
|
|
||||||
|
|
||||||
<div class="code-block code-block--input">
|
|
||||||
{% highlight liquid %}
|
|
||||||
{% raw %}
|
|
||||||
{{ pages.about-us.title }}
|
|
||||||
{{ pages["about-us"].title }}
|
|
||||||
{% endraw %}
|
|
||||||
{% endhighlight %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="code-block code-block--output">
|
|
||||||
{% highlight text %}
|
|
||||||
About Us
|
|
||||||
About Us
|
|
||||||
{% endhighlight %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
In the example above, notice that we are using `pages` as opposed to `page`.
|
|
||||||
@@ -42,9 +42,9 @@ Hello Adam!
|
|||||||
|
|
||||||
Tags can be categorized into three types:
|
Tags can be categorized into three types:
|
||||||
|
|
||||||
- [Control flow](/tags/control-flow)
|
- [Control flow]({{ "/tags/control-flow" | prepend: site.baseurl }})
|
||||||
- [Iteration](/tags/iteration)
|
- [Iteration]({{ "/tags/iteration" | prepend: site.baseurl }})
|
||||||
- [Variable assignments](/tags/variable)
|
- [Variable assignments]({{ "/tags/variable" | prepend: site.baseurl }})
|
||||||
|
|
||||||
You can read more about each type of tag in their respective sections.
|
You can read more about each type of tag in their respective sections.
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ In the example below, the string "Tobi" is not a boolean, but it is truthy in a
|
|||||||
{% raw %}
|
{% raw %}
|
||||||
{% assign tobi = "Tobi" %}
|
{% assign tobi = "Tobi" %}
|
||||||
|
|
||||||
{% if tobi == true %}
|
{% if tobi %}
|
||||||
This condition will always be true.
|
This condition will always be true.
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
```
|
```
|
||||||
|
|
||||||
[Strings](/basics/types/#string), even when empty, are truthy. The example below will result in empty HTML tags if `settings.fp_heading` is empty:
|
[Strings]({{ "/basics/types/#string" | prepend: site.baseurl }}), even when empty, are truthy. The example below will result in empty HTML tags if `settings.fp_heading` is empty:
|
||||||
|
|
||||||
```liquid
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
@@ -38,23 +38,9 @@ In the example below, the string "Tobi" is not a boolean, but it is truthy in a
|
|||||||
<h1></h1>
|
<h1></h1>
|
||||||
```
|
```
|
||||||
|
|
||||||
[EmptyDrops](/basics/types/#emptydrop) are also truthy. In the example below, if `settings.page` is an empty string or set to a hidden or deleted object, you will end up with an EmptyDrop. The result is an empty `div`:
|
|
||||||
|
|
||||||
```liquid
|
|
||||||
{% raw %}
|
|
||||||
{% if pages[settings.page] %}
|
|
||||||
<div>{{ pages[settings.page].content }}</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endraw %}
|
|
||||||
```
|
|
||||||
|
|
||||||
```html
|
|
||||||
<div></div>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Falsy
|
## Falsy
|
||||||
|
|
||||||
The falsy values in Liquid are [`nil`](/basics/types/#nil) and [`false`](/basics/types/#boolean).
|
The falsy values in Liquid are [`nil`]({{ "/basics/types/#nil" | prepend: site.baseurl }}) and [`false`]({{ "/basics/types/#boolean" | prepend: site.baseurl }}).
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
|
|||||||
+4
-43
@@ -9,9 +9,8 @@ Liquid objects can have one of six types:
|
|||||||
- [Boolean](#boolean)
|
- [Boolean](#boolean)
|
||||||
- [Nil](#nil)
|
- [Nil](#nil)
|
||||||
- [Array](#array)
|
- [Array](#array)
|
||||||
- [EmptyDrop](#emptydrop)
|
|
||||||
|
|
||||||
You can initialize Liquid variables with the [assign](/tags/#assign) or [capture](/tags/#capture) tags.
|
You can initialize Liquid variables with the [assign]({{ "/tags/variable/#assign" | prepend: site.baseurl }}) or [capture]({{ "/tags/variable/#capture" | prepend: site.baseurl }}) tags.
|
||||||
|
|
||||||
## String
|
## String
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ 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 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) 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" | 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:
|
In the following example, if the user does not exist (that is, `user` returns `nil`), Liquid will not print the greeting:
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ Arrays hold lists of variables of any type.
|
|||||||
|
|
||||||
### Accessing items in arrays
|
### 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/).
|
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 }}).
|
||||||
|
|
||||||
```liquid
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
@@ -119,42 +118,4 @@ Adam
|
|||||||
|
|
||||||
You cannot initialize arrays using only Liquid.
|
You cannot initialize arrays using only Liquid.
|
||||||
|
|
||||||
You can, however, use the [split](/filters/split) 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 by name. 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 %}
|
|
||||||
```
|
|
||||||
|
|
||||||
EmptyDrop objects only have one attribute, `empty?`, which is always *true*.
|
|
||||||
|
|
||||||
Collections and pages that *do* exist do not have an `empty?` attribute. Their `empty?` is "falsy", which means that calling it inside an if statement will return *false*. When using an `unless` statement on existing collections and pages, `empty?` will return `true`.
|
|
||||||
|
|
||||||
### Checking for emptiness
|
|
||||||
|
|
||||||
Using the `empty?` attribute, you can check to see if an object exists or not before you access any of its attributes.
|
|
||||||
|
|
||||||
```liquid
|
|
||||||
{% raw %}
|
|
||||||
{% unless pages.about.empty? %}
|
|
||||||
<!-- This will only print if the page with handle 'about' is not empty -->
|
|
||||||
<h1>{{ pages.frontpage.title }}</h1>
|
|
||||||
<div>{{ pages.frontpage.content }}</div>
|
|
||||||
{% endunless %}
|
|
||||||
{% endraw %}
|
|
||||||
```
|
|
||||||
|
|
||||||
If you don't check for emptiness first, Liquid might print empty HTML elements to the page:
|
|
||||||
|
|
||||||
```html
|
|
||||||
<h1></h1>
|
|
||||||
<div></div>
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ title: divided_by
|
|||||||
|
|
||||||
Divides a number by the specified number.
|
Divides a number by the specified number.
|
||||||
|
|
||||||
The result is rounded down to the nearest integer (that is, the [floor](/filters/floor)).
|
The result is rounded down to the nearest integer (that is, the [floor]({{ "/filters/floor" | prepend: site.baseurl }})).
|
||||||
|
|
||||||
```liquid
|
```liquid
|
||||||
{% raw %}
|
{% raw %}
|
||||||
|
|||||||
Reference in New Issue
Block a user