mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Auto-generate more code samples, plus other fixes and improvements
This commit is contained in:
@@ -19,7 +19,7 @@ Liquid code can be categorized into [**objects**](#objects), [**tags**](#tags),
|
||||
|
||||
<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`.
|
||||
@@ -79,5 +79,5 @@ Multiple filters can be used on one output. They are applied from left to right.
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
Hello Adam!
|
||||
{{ "adam!" | capitalize | prepend: "Hello " }}
|
||||
```
|
||||
|
||||
@@ -15,7 +15,7 @@ Returns the absolute value of a number.
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
17
|
||||
{{ -17 | abs }}
|
||||
```
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
@@ -27,7 +27,7 @@ Returns the absolute value of a number.
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
4
|
||||
{{ 4 | abs }}
|
||||
```
|
||||
|
||||
`abs` will also work on a string if the string only contains a number.
|
||||
@@ -41,5 +41,5 @@ Returns the absolute value of a number.
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
19.86
|
||||
{{ "-19.86" | abs }}
|
||||
```
|
||||
|
||||
@@ -13,7 +13,7 @@ Limits a number to a minimum value.
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```
|
||||
```text
|
||||
5
|
||||
```
|
||||
|
||||
@@ -25,6 +25,6 @@ Limits a number to a minimum value.
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```
|
||||
```text
|
||||
4
|
||||
```
|
||||
|
||||
@@ -13,7 +13,7 @@ Limits a number to a maximum value.
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```
|
||||
```text
|
||||
4
|
||||
```
|
||||
|
||||
@@ -25,6 +25,6 @@ Limits a number to a maximum value.
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```
|
||||
```text
|
||||
3
|
||||
```
|
||||
|
||||
@@ -14,7 +14,7 @@ Makes the first character of a string capitalized.
|
||||
|
||||
<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:
|
||||
@@ -28,5 +28,5 @@ Title
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
My great title
|
||||
{{ "my great title" | capitalize }}
|
||||
```
|
||||
|
||||
@@ -13,20 +13,20 @@ For this example, assume `site.pages` is an array of content pages for a website
|
||||
{% 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.
|
||||
@@ -37,16 +37,16 @@ By using `compact` when we create our `site_categories` array, we can remove all
|
||||
{% 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
|
||||
```
|
||||
|
||||
@@ -8,17 +8,13 @@ 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 }}
|
||||
{{ "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>
|
||||
|
||||
@@ -8,17 +8,13 @@ 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 }}
|
||||
{{ "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>
|
||||
|
||||
@@ -13,16 +13,16 @@ In this example, assume the object `site.pages` contains all the metadata for a
|
||||
{% 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
|
||||
```
|
||||
|
||||
@@ -8,13 +8,11 @@ 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" }}
|
||||
{{ "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" }}
|
||||
```
|
||||
|
||||
@@ -22,7 +22,7 @@ Returns the number of characters in a string or the number of items in an array.
|
||||
{% raw %}
|
||||
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
|
||||
|
||||
{{ my_array | size }}
|
||||
{{ my_array.size }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
@@ -30,7 +30,7 @@ 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.
|
||||
|
||||
@@ -14,5 +14,5 @@ Decodes a string that has been encoded as a URL or by [`url_encode`]({{ '/filter
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
'Stop!' said Fred
|
||||
{{ "%27Stop%21%27+said+Fred" | url_decode }}
|
||||
```
|
||||
|
||||
@@ -203,6 +203,24 @@ Uses for `cycle` include:
|
||||
|
||||
`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.
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% 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
|
||||
one
|
||||
one
|
||||
two
|
||||
two
|
||||
```
|
||||
|
||||
## tablerow
|
||||
|
||||
Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` HTML tags.
|
||||
|
||||
Reference in New Issue
Block a user