mirror of
https://github.com/kemko/liquid.git
synced 2026-01-03 08:45:42 +03:00
WIP: Adding missing filters
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
---
|
||||
title: round
|
||||
---
|
||||
|
||||
Rounds the output to the nearest integer or specified number of decimals.
|
||||
|
||||
| Input | Output |
|
||||
|:-------------------------------------------|:-------|
|
||||
| {% raw %}`{{ 4.6 | round }}` {% endraw %} | 5 |
|
||||
| {% raw %}`{{ 4.3 | round }}` {% endraw %} | 4 |
|
||||
| {% raw %}`{{ 4.5612 | round: 2 }}` {% endraw %} | 4.56 |
|
||||
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
---
|
||||
title: slice
|
||||
---
|
||||
|
||||
The <code>slice</code> filter returns a substring, starting at the specified index. An optional second parameter can be passed to specify the length of the substring. If no second parameter is given, a substring of one character will be returned.
|
||||
|
||||
|
||||
| Input | Output |
|
||||
|:------------------------------------------------|:-------|
|
||||
| {% raw %}`{{ "hello" | slice: 0 }}`{% endraw %} | h |
|
||||
| {% raw %}`{{ "hello" | slice: 1 }}`{% endraw %} | e |
|
||||
| {% raw %}`{{ "hello" | slice: 1, 3 }}`{% endraw %} | ell |
|
||||
|
||||
|
||||
If the passed index is negative, it is counted from the end of the string.
|
||||
|
||||
| Input | Output |
|
||||
|:------------------------------------------------|:-------|
|
||||
| {% raw %}`{{ "hello" | slice: -3, 2 }}`{% endraw %} | ll |
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
---
|
||||
title: truncate
|
||||
---
|
||||
|
||||
|
||||
<p>Truncates a string down to 'x' characters, where x is the number passed as a parameter. An ellipsis (...) is appended to the string and is included in the character count.</p>
|
||||
|
||||
| Input | Output |
|
||||
|:-------------------------------------------|:-------|
|
||||
| {% raw %}`{{ "The cat came back the very next day" | truncate: 10 }}`{% endraw %} | "The cat..." |
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
---
|
||||
title: truncatewords
|
||||
---
|
||||
|
||||
|
||||
<p>Truncates a string down to 'x' words, where x is the number passed as a parameter. An ellipsis (...) is appended to the truncated string.</p>
|
||||
|
||||
| Input | Output |
|
||||
|:-------------------------------------------|:-------|
|
||||
| {% raw %}`{{ "The cat came back the very next day" | truncatewords: 4 }}`{% endraw %} | The cat came back...|
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
---
|
||||
title: uniq
|
||||
---
|
||||
|
||||
|
||||
<p>Removes any duplicate instances of an element in an array.</p>
|
||||
|
||||
| Input | Output |
|
||||
|:-------------------------------------------|:-------|
|
||||
| {% raw %}`{% assign fruits = "orange apple banana apple orange" %} {{ fruits | split: ' ' | uniq | join: ' ' }}`{% endraw %} | orange apple banana |
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
---
|
||||
title: upcase
|
||||
---
|
||||
|
||||
<p>Converts a string into uppercase.</p>
|
||||
|
||||
|
||||
| Input | Output |
|
||||
|:-------------------------------------------|:-------|
|
||||
| {% raw %}`{{ 'loud noises' | upcase }}`{% endraw %} | LOUD NOISES |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user