Array helpers
after
Returns the items of an array after a starting index. Opposite of before.
Parameters:
array{Array}: Collectionn{Number}: Starting index (number of items to exclude)
Returns {Array} array excluding first n items.
Example:
arrayify
Returns a value as a single-item array.
Parameters:
value{any}
Returns an array.
Example:
before
Parameters:
array{Array}n{Number}
Returns array excluding items after the index n.
Opposite of after.
Example:
eachIndex
Implementation of the default Handlebars loop helper {{#each}} adding index (0-based index) to the loop content
Parameters:
array{Array}options{Object}returns{String}
Returns: {String}
Example:
filter
Block helper: filters array and renders the block for values that evaluate to true; otherwise the inverse block is returned.
Parameters:
array{Array}value{any}options{Object}
Returns: {String}
Example:
first
Returns the first item, or first n items, of an array
Parameters:
array{Array}n{Number}: Number of items to return, starting at 0. Optional.
Returns: {Array}
Example:
forEach
Iterates over each item in array and exposes the current item as context to the inner block.
The helper also exposes the following variables to the inner block:
indextotalisFirstisLast
Also, @index is exposed as a private variable, and additional private variables may be defined as hash arguments.
Parameters:
array{Array}
Returns {String}
Example:
inArray
Block helper: renders the block if array contains value. Optionally specify an inverse block to render when the array does not have the given value.
Parameters:
array{Array}value{any}options{Object}
Returns {String}
Example:
isArray
Returns true if value is an ES5 array.
Parameters:
value{any}: the value to test
Returns {Boolean}
Example:
itemAt
Returns the item from array at index idx.
Parameters:
array{Array}idx{Number}
Returns {any}
Example:
join
Join all elements of array into a string, optionally using a given separator.
Parameters:
array{Array}separator{String}: The separator to use. Defaults to,.
Returns {String}
Example:
last
Returns the last item, or last n items of value. Opposite of first.
Parameters:
value{Array|String}: Array or stringn{Number}: Number of items to return from the end of the array.
Returns: {Array or String}
Example:
lengthEqual
Alias for equalsLength
map
Returns a new array, created by calling function on each element of the given array.
Parameters:
array{Array}fn{Function}
Returns {String}
Example:
reverse
Reverse the elements in an array, or the characters in a string.
Parameters:
value{Array|Object}
Returns {Array|String} Returns the reversed string or array.
Example:
sort
Sort array. If its items are objects, optional key specifies the sort.
Parameters:
array{Array}: the array to sort.key{String|Function}: The object key to sort by, or sorting function.
Returns {Array}
Example:
sortBy
Sort an array. If its items are objects, optional props specifies the sort.
Parameters:
array{Array}: the array to sort.props{String|Function}: One or more properties to sort by, or sorting functions to use.
Returns {String}
Example:
withAfter
Use the items in array after index idx as context inside a block. Opposite of withBefore.
Parameters:
array{Array}idx{Number}options{Object}
Returns {Array}
Example:
withBefore
Use the items in the array before the specified index as context inside a block. Opposite of withAfter.
Parameters:
array{Array}idx{Number}options{Object}
Returns {Array}
Example:
withFirst
Use the first item in a collection inside a Handlebars block expression. Opposite of withLast.
Parameters:
array{Array}idx{Number}options{Object}
Returns {String}
Example:
withGroup
Block helper: groups array elements by group size.
Parameters:
array{Array}: The array to iterate oversize{Number}: The desired length of each array "group"options{Object}: Handlebars options
Returns {String}
Example:
withLast
Use the last or last n items in array as context inside a block. Opposite of withFirst.
Parameters:
array{Array}idx{Number}: The starting index.options{Object}
Returns {String}
Example:
withSort
Block helper: sorts a collection and exposes the sorted collection as context inside the block.
Parameters:
array{Array}prop{String}options{Object}: Specify reverse="true" to reverse the array.
Returns {String}
Example: