mirror of
https://github.com/pantor/inja.git
synced 2026-08-18 13:23:19 +00:00
add first and last function
This commit is contained in:
@@ -167,9 +167,13 @@ render("Hello {{ lower(neighbour) }}!", data); // "Hello peter!"
|
||||
// Range function, useful for loops
|
||||
render("{% for i in range(4) %}{{ index1 }}{% endfor %}", data); // "1234"
|
||||
|
||||
// Length function (but please don't combine with range, use list directly...)
|
||||
// Length function (please don't combine with range, use list directly...)
|
||||
render("I count {{ length(guests) }} guests.", data); // "I count 3 guests."
|
||||
|
||||
// Get first and last element in a list
|
||||
render("{{ first(guests) }} was first.", data); // "Jeff was first."
|
||||
render("{{ last(guests) }} was last.", data); // "Tom was last."
|
||||
|
||||
// Round numbers to a given precision
|
||||
render({{ round(3.1415, 0) }}, data); // 3
|
||||
render({{ round(3.1415, 3) }}, data); // 3.142
|
||||
|
||||
Reference in New Issue
Block a user