mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Redcarpetify index; edit default filter
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
title: default
|
title: default
|
||||||
---
|
---
|
||||||
|
|
||||||
`default` offers a means of having a fallback in case your value doesn't exist. `default` will use its substitute if the left side is `nil`, `false`, or empty.
|
`default` lets you specify a fallback in case a value doesn't exist. `default` will show its value if the left side is `nil`, `false`, or empty.
|
||||||
|
|
||||||
In this example, `product_price` is not defined, so the default value is used.
|
In this example, `product_price` is not defined, so the default value is used.
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,15 @@ Objects and variable names are denoted by double curly braces: `{% raw %}{{{% en
|
|||||||
|
|
||||||
For example, you can show basic content like a page title using a Liquid object:
|
For example, you can show basic content like a page title using a Liquid object:
|
||||||
|
|
||||||
| Liquid | Output |
|
```liquid
|
||||||
|:----------------------------------------|:---------|
|
{% raw %}
|
||||||
| {% raw %}`{{ page.title }}`{% endraw %} | Overview |
|
{{ page.title }}
|
||||||
|
{% endraw %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
Overview
|
||||||
|
```
|
||||||
|
|
||||||
In this case, Liquid is rendering the content of an object called `page.title`, and that object contains the text `Overview`.
|
In this case, Liquid is rendering the content of an object called `page.title`, and that object contains the text `Overview`.
|
||||||
|
|
||||||
@@ -40,27 +46,20 @@ Tag markup does not resolve to text. This means that you can assign variables an
|
|||||||
|
|
||||||
#### Conditionals
|
#### Conditionals
|
||||||
|
|
||||||
For example, you can change what information Liquid shows using conditionals:
|
Conditionals can change the information Liquid shows using programming logic:
|
||||||
|
|
||||||
<p class="input">Liquid</p>
|
```liquid
|
||||||
<div>
|
|
||||||
{% highlight liquid %}
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
|
|
||||||
{% if user %}
|
{% if user %}
|
||||||
Hello {{ user.name }}!
|
Hello {{ user.name }}!
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="output">Output</p>
|
```text
|
||||||
<div>
|
|
||||||
{% highlight text %}
|
|
||||||
Hello Adam!
|
Hello Adam!
|
||||||
{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
This conditional statement `if user` checks to see if an object called `user` exists. If the condition is *true* (that is, if there is a `user`), Liquid shows any content that is contained between the `if` and `endif` tags.
|
This conditional statement `if user` checks to see if an object called `user` exists. If the condition is *true* (that is, if there is a `user`), Liquid shows any content that is contained between the `if` and `endif` tags.
|
||||||
|
|
||||||
@@ -70,9 +69,7 @@ In this case, our user's `name` is Adam, so the template prints `Hello Adam!`.
|
|||||||
|
|
||||||
You can also use tags to loop over a list or array of objects:
|
You can also use tags to loop over a list or array of objects:
|
||||||
|
|
||||||
<p class="input">Liquid</p>
|
```liquid
|
||||||
<div>
|
|
||||||
{% highlight liquid %}
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
|
|
||||||
{% for item in collection %}
|
{% for item in collection %}
|
||||||
@@ -80,18 +77,14 @@ You can also use tags to loop over a list or array of objects:
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="output">Output</p>
|
```text
|
||||||
<div>
|
|
||||||
{% highlight text %}
|
|
||||||
I have a shirt
|
I have a shirt
|
||||||
I have a pants
|
I have a pants
|
||||||
I have a banana
|
I have a banana
|
||||||
I have a bucket
|
I have a bucket
|
||||||
{% endhighlight %}
|
```
|
||||||
</div>
|
|
||||||
|
|
||||||
The statement `for item in collection` tells Liquid to show the content between the `for` and `endfor` tags one time for every `item` in the `collection` object.
|
The statement `for item in collection` tells Liquid to show the content between the `for` and `endfor` tags one time for every `item` in the `collection` object.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user