mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Minor updates, switch Pigments to Rouge
This commit is contained in:
@@ -13,7 +13,7 @@ For example, a page with the title "About Us" can be accessed in Liquid via its
|
||||
{% endraw %}
|
||||
{% endhighlight %}
|
||||
|
||||
## Creating handles
|
||||
### 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.
|
||||
|
||||
@@ -23,46 +23,28 @@ Handles also determine the URL of their corresponding objects. For example, a pa
|
||||
|
||||
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 (how?)
|
||||
You can change an object's handle manually (TK how to change a handle manually)
|
||||
|
||||
## Accessing attributes via the handle", "attributes-handle
|
||||
### 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.
|
||||
|
||||
<p class="input">Input</p>
|
||||
<div>
|
||||
{% highlight html %}{% raw %}
|
||||
{% highlight liquid %}
|
||||
{% raw %}
|
||||
{{ pages.about-us.title }}
|
||||
{{ pages["about-us"].title }}
|
||||
{% endraw %}{% endhighlight %}
|
||||
{% endraw %}
|
||||
{% endhighlight %}
|
||||
</div>
|
||||
|
||||
<p class="output">Output</p>
|
||||
<div>
|
||||
{% highlight html %}{% raw %}
|
||||
{% highlight text %}
|
||||
About Us
|
||||
About Us
|
||||
{% endraw %}{% endhighlight %}
|
||||
{% endhighlight %}
|
||||
</div>
|
||||
|
||||
In the example above, notice that we are using `pages` as opposed to `page`.
|
||||
|
||||
You can also pass in Customize theme page objects using this notation. This is handy for theme designers who wish to give the users of their themes the ability to select which content to display in their theme.
|
||||
|
||||
<p class="input">Input</p>
|
||||
<div>
|
||||
{% highlight html %}{% raw %}
|
||||
{% for product in collections[settings.home_featured_collection].products %}
|
||||
{{ product.title }}
|
||||
{% endfor %}
|
||||
{% endraw %}{% endhighlight %}
|
||||
</div>
|
||||
|
||||
<p class="output">Output</p>
|
||||
<div>
|
||||
{% highlight html %}{% raw %}
|
||||
Awesome Shoes
|
||||
Cool T-Shirt
|
||||
Wicked Socks
|
||||
{% endraw %}{% endhighlight %}
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Operators
|
||||
---
|
||||
|
||||
Liquid has access to all of the logical and comparison operators.
|
||||
Liquid includes many logical and comparison operators.
|
||||
|
||||
### Basic Operators
|
||||
|
||||
@@ -17,7 +17,7 @@ Liquid has access to all of the logical and comparison operators.
|
||||
<td>does not equal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><pre>></pre></td>
|
||||
<td><pre>></pre></td>
|
||||
<td>greater than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -25,9 +25,8 @@ Liquid has access to all of the logical and comparison operators.
|
||||
<td>less than</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><pre>>=</pre></td>
|
||||
<td>greater than or equal to</td>
|
||||
|
||||
<td><pre>>=</pre></td>
|
||||
<td>greater than or equal to</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><pre><=</pre></td>
|
||||
@@ -35,84 +34,51 @@ Liquid has access to all of the logical and comparison operators.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><pre>or</pre></td>
|
||||
<td>condition A <strong>or</strong> condition B</td>
|
||||
<td>logical or</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><pre>and</pre></td>
|
||||
<td>condition A <strong>and</strong> condition B</td>
|
||||
<td>logical and</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**Examples:**
|
||||
For example:
|
||||
|
||||
<div>
|
||||
{% highlight html %}{% raw %}
|
||||
{% highlight liquid %}{% raw %}
|
||||
{% if product.title == "Awesome Shoes" %}
|
||||
These shoes are awesome!
|
||||
These shoes are awesome!
|
||||
{% endif %}
|
||||
{% endraw %}{% endhighlight %}
|
||||
</div>
|
||||
|
||||
Operators can be chained together.
|
||||
You can use multiple operators in a tag:
|
||||
|
||||
<div>
|
||||
{% highlight html %}{% raw %}
|
||||
{% highlight liquid %}{% raw %}
|
||||
{% if product.type == "Shirt" or product.type == "Shoes" %}
|
||||
This is a shirt or a shoe.
|
||||
This is a shirt or a pair of shoes.
|
||||
{% endif %}
|
||||
{% endraw %}{% endhighlight %}
|
||||
</div>
|
||||
|
||||
### contains
|
||||
|
||||
`contains` checks for the presence of a substring inside a string.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Contains operator
|
||||
|
||||
<code>contains</code> checks for the presence of a substring inside a string.
|
||||
|
||||
|
||||
{% highlight html %}{% raw %}
|
||||
{% highlight liquid %}{% raw %}
|
||||
{% if product.title contains 'Pack' %}
|
||||
This product's title contains the word Pack.
|
||||
{% endif %}
|
||||
{% endraw %}{% endhighlight %}
|
||||
|
||||
`contains` can also check for the presence of a string in an array of strings.
|
||||
|
||||
<code>contains</code> can also check for the presence of a string in an array of strings.
|
||||
|
||||
{% highlight html %}{% raw %}
|
||||
{% highlight liquid %}{% raw %}
|
||||
{% if product.tags contains 'Hello' %}
|
||||
This product has been tagged with 'Hello'.
|
||||
{% endif %}
|
||||
{% endraw %}{% endhighlight %}
|
||||
|
||||
|
||||
You **cannot** check for the presence of an object in an array of objects using contains. This will not work:
|
||||
|
||||
{% highlight html %}{% raw %}
|
||||
{% if product.collections contains 'Sale' %}
|
||||
One of the collections this product belongs to is the Sale collection.
|
||||
{% endif %}
|
||||
{% endraw %}{% endhighlight %}
|
||||
|
||||
This will work:
|
||||
|
||||
{% highlight html %}{% raw %}
|
||||
{% assign in_sale_collection = false %}
|
||||
{% for collection in product.collections %}
|
||||
{% if in_sale_collection == false and collection.title == 'Sale' %}
|
||||
{% assign in_sale_collection = true %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if in_sale_collection %}
|
||||
One of the collections this product belongs to is the Sale collection.
|
||||
{% endif %}
|
||||
{% endraw %}{% endhighlight %}
|
||||
|
||||
|
||||
`contains` is can only search strings. You cannot use it to check for an object in an array of objects.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
baseurl: "" # the subpath of your site, e.g. /blog/
|
||||
url: "http://liquidmarkup.org" # the base hostname & protocol for your site
|
||||
markdown: kramdown
|
||||
highlighter: rouge
|
||||
permalink: /:year/:month/:day/:basename:output_ext
|
||||
collections:
|
||||
basics:
|
||||
|
||||
@@ -173,6 +173,10 @@ table {
|
||||
border: 1px solid #ddd;
|
||||
padding: 6px 13px;
|
||||
}
|
||||
/* Don't use a margin on code samples within tables */
|
||||
pre {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
td {
|
||||
|
||||
Reference in New Issue
Block a user