Manipulate items in arrays and objects. Includes "first", "last", "after", "before", "join", "sort", "length", "empty", "any", "inArray", "eachIndex" and "eachProperty".
first
Returns the first item in a collection.
Parameters
None.
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{first collection}}
Result
Amy Wong
withFirst
Use the first item in a collection inside a block.
Parameters
None.
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{#withFirst collection}}
<p>{{this}} is smart.</p>
{{/withFirst}}
Result
<p>Amy Wong is smart.</p>
last
Returns the last item in a collection.
Parameters
None.
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{last collection}}
Result
Scruffy
withLast
Use the last item in a collection inside a block.
Parameters
None.
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{#withLast collection}}
<p>{{this}} is lazy.</p>
{{/withLast}}
Result
<p>Scruffy is lazy.</p>
after
Returns all of the items in the collection after the specified count.
Parameters
count [int] - How many items to omit from the beginning. (Required)
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{after collection 5}}
Result
Leela, Professor Farnsworth, Scruffy
withAfter
Use all of the items in the collection after the specified count inside a block.
Parameters
count [int] - How many items to omit from the beginning. (Required)
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{#withAfter collection 5}}
{{this}}
{{/withAfter}}
Result
Leela Professor Farnsworth Scruffy
before
Returns all of the items in the collection before the specified count.
Parameters
count [int] - How many items to omit from the end. (Required)
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{before collection 5}}
Result
Amy Wong, Bender, Dr. Zoidberg
withBefore
Use all of the items in the collection before the specified count inside a block.
Parameters
count [int] - How many items to omit from the end. (Required)
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{#withBefore collection 5}}
{{this}}
{{/withBefore}}
Result
Amy Wong Bender Dr. Zoidberg
join
Joins all elements of a collection into a string using the separator specified.
Parameters
separator [string] - A string to use as a separator between the items. (Optional)
Example
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{join collection " & "}}
Result
Amy Wong & Bender & Dr. Zoidberg & Fry & Hermes Conrad & Leela & Professor Farnsworth & Scruffy
sort
Returns the collection sorted alphabetically.
Parameters
None.
Example
collection = ['Bender', 'Scruffy', 'Dr. Zoidberg', 'Hermes Conrad', 'Amy Wong', 'Leela', 'Professor Farnsworth', 'Fry']
{{sort collection}}
Result
Amy Wong, Bender, Dr. Zoidberg, Fry, Hermes Conrad, Leela, Professor Farnsworth, Scruffy
length
Returns the length of the collection.
Parameters
None
Example
collection = ['Dr. Zoidberg', 'Fry', 'Amy Wong', 'Professor Farnsworth', 'Bender', 'Hermes Conrad', 'Leela', 'Scruffy']
{{length collection}}
Result
8
lengthEqual
Conditionally render a block based on the length of a collection.
Parameters
length [int] - The value to test against. (Required)
Example
collection = [{
'name': 'Leela',
'deliveries': 8021
}, {
'name': 'Fry',
'deliveries': 12
},{
'name': 'Bender',
'deliveries': 239
}]
{{#lengthEqual collection 3}}
There are 3 people in Planet Express.
{{else}}
This is not Planet Express.
{{/lengthEqual}}
Result
There are 3 people in Planet Express.
empty
Conditionally render a block if the collection is empty.
Parameters
None
Example
collection = []
{{#empty collection}}
Good news everyone!
{{else}}
Bad news everyone!
{{/empty}}
Result
Good news everyone!
any
Conditionally render a block if the collection isn't empty. Opposite of empty.
Parameters
None
Example
collection = ['Professor Farnsworth']
{{#any collection}}
Good news everyone!
{{else}}
Bad news everyone!
{{/any}}
Result
Good news everyone!
inArray
Conditionally render a block if a specified value is in the collection.
Parameters
value [string|int] - A value to test against. (Required)
Example
collection = ['Professor Farnsworth', 'Fry', 'Bender']
{{#inArray collection "Fry"}}
I'm walking on sunshine!
{{else}}
I'm walking in darkness.
{{/inArray}}
Result
I'm walking on sunshine!
eachIndex
Renders a block using the array and each item's index.
Parameters
None
Example
collection = ['Professor Farnsworth', 'Fry', 'Bender']
{{#eachIndex collection}}
{{item}} is {{index}}
{{/eachIndex}}
Result
Professor Farnsworth is 0, Fry is 1, Bender is 2
eachProperty
Uses the key and value of each property in an object to render a block.
Parameters
None
Example
collection = {"Fry": 3, "Bender": 120}
{{#eachProperty collection}}
{{key}} - {{value}}
{{/eachProperty}}
Result
Fry - 3 Bender - 120