harrydeluxe / php-liquid

A PHP port of Ruby's Liquid Templates
http://www.delacap.com/artikel/Liquid-Templates/
MIT License
239 stars 119 forks source link

Improving for tag parameters(limit, offset, reversed) #35

Closed chenos closed 7 years ago

chenos commented 7 years ago

Multi-digit Support

{% for i in (20..30) %} {{i}} {% endfor %}

Improving for tag parameters(limit, offset, reversed)

{% for i in (1..10) limit:1 %} {{i}} {% endfor %}
{% for i in (1..5) offset:3 %} {{i}} {% endfor %}
{% for i in (1..5) reversed %} {{i}} {% endfor %}

All values in Liquid are truthy except nil (null in php) and false. Zero, empty string and empty array are all truthy.

For loop else

{% for item in array %}+{% else %}-{% endfor %}

Use square bracket [ ] notation to access a specific item in an array.

{{ a.b.c }}
{{ a['b'].c }}
{{ a.b['c'] }}
{{ a['b']['c'] }}
{% assign b = 'b' %}{{ a[b]['c'] }}

Fixing float variable bug.

{{ 1 | plus: 1.0 }}  // output  2.0