mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
Fix: respect parameter order when using "for ... reversed" (#231)
* fix: spelling * fix: respect param order for reversed * docs: add for-reversed order details * perf: improve performance by 4x by simplified parseFile BREAKING CHANGES: - previously deprecated `getTemplate()` and `getTemplateSync()` not no longer supported - `opts` no longer support dynamic set in `parseFile()`, `renderFile()` arguments * perf: parse filenames in parse() insteadof render() * docs: update description of LiquidJS Co-authored-by: harttle <[email protected]>
This commit is contained in:
committed by
Jun Yang
co-authored by
harttle
parent
9012133e07
commit
fb787e8847
+28
-2
@@ -106,7 +106,7 @@ There's a `forloop` object available inside `for` loops. It's used to indicate t
|
||||
The `forloop.first`, `forloop.last` and `forloop.length` property:
|
||||
|
||||
Input
|
||||
```
|
||||
```liquid
|
||||
{% for i in (1..5) %}
|
||||
{%- if forloop.first == true -%} First
|
||||
{%- elsif forloop.last == true -%} Last
|
||||
@@ -116,7 +116,7 @@ Input
|
||||
```
|
||||
|
||||
Output
|
||||
```
|
||||
```text
|
||||
First
|
||||
5
|
||||
5
|
||||
@@ -218,3 +218,29 @@ Output
|
||||
```text
|
||||
6 5 4 3 2 1
|
||||
```
|
||||
|
||||
When used with additional parameters, order is important. Leading with `reversed` reverses the order of the loop before executing the other parameters.
|
||||
|
||||
Input
|
||||
```liquid
|
||||
{% for i in (1..8) reversed limit: 4 %}
|
||||
{{ i }}
|
||||
{% endfor %}
|
||||
```
|
||||
|
||||
Output
|
||||
```text
|
||||
8 7 6 5
|
||||
```
|
||||
|
||||
Input
|
||||
```liquid
|
||||
{% for i in (1..8) limit: 4 reversed %}
|
||||
{{ i }}
|
||||
{% endfor %}
|
||||
```
|
||||
|
||||
Output
|
||||
```text
|
||||
4 3 2 1
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user