Tags
Array & Object Tags
{split;input;separator}
Splits input
into an array at separator
. separator
can be an arbitrary string or regex pattern.
Name | Type | Description |
---|---|---|
input | string | The string to split. |
separator | string | The separator or pattern to split the string by. |
{split;one,two,three;,} // {[one;two;three]}
{split;woah party tricks;/ +/g} // {[woah;party;tricks]}
{split;one,two,three;/(,)/g} // {[one;,;two;,;three]}, you can use groups to keep the separator in the output array.
{join;array;separator}
Join the items of an array together with the given separator.
Name | Type | Default | Description |
---|---|---|---|
array | array | The array to join. | |
separator | string | , (space) | The separator to use between the items of the array. |
{=array;{[one;two;three]}}
{join;{$array};,} // one,two,three
{push return;array;value}
Adds an item to the end of an array.
This will mutate the original array, which is why nothing is returned by default.
Name | Type | Description |
---|---|---|
array | array | The array to add the item to. |
value | any | The item to add to the array. |
return | boolean? | Whether to return the modified array |
{=array;{[one]}}
{push;{$array};two} // no output
{$array} // {[one;two]}
{push return;{$array};three} // {[one;two;three]}
{pop}
Returns and deletes the last item of an array.
Name | Type | Description |
---|---|---|
array | array | The array to pop the item from |
{=array;{[one;two;three]}}
{pop;{$array}} // three
{$array} // {[one;two]}
{shift}
Returns and deletes the first item of an array.
Name | Type | Description |
---|---|---|
array | array | The array to shift the item from |
{=array;{[one;two;three]}}
{shift;{$array}} // one
{$array} // {[two;three]}
{unshift return;array;value}
Adds an item to the front of an array. Essentially the same as {push}
but the item is added to the beginning of the array.
Name | Type | Description |
---|---|---|
array | array | The array to add the item to. |
value | any | The item to add to the array. |
return | boolean? | Whether to return the modified array |
{=array;{[three]}}
{unshift;{$array};two} // no output
{$array} // {[two;three]}
{unshift return;{$array};one} // {[one;two;three]}
{for;init;iterable;body}
This tag is part of the General
expensive group.
Iterates over array items until {break}
is encountered or it reaches the end of the array.
Name | Type | Description |
---|---|---|
init | any | Value that will be set before each iteration of the loop, commonly used for assigning the current item to a variable. |
iterable | array | The array to iterate over. |
body | string | The pella code to run for each item in iterable . |
{=array;{[one;two;three]}}
// regular format
{for;{=item};{$array};{$item}} // one two three
// block format
[#for;{=item};{$array}]
{$item}
[/for]
{keys;object}
Get the keys of an object. Useful when you want to iterate over the keys or values of an object. Only top-level keys are returned
Name | Type | Description |
---|---|---|
object | object | The object to get the keys of. |
{=object.key;value}
{=object.nested.key;value}
{keys;{$object}} // {[key;nested]}
{includes;array;item}
Check whether an array includes an item.
Name | Type | Description |
---|---|---|
array | array | The array to search in |
item | any | The item to search for. |
{=array;{[one;two;three]}}
{includes;{$array};two} // true
{sort reverse;array;key}
Sort an array. Returns a new array and does not mutate the original.
Name | Type | Default | Description |
---|---|---|---|
array | array | The array to sort | |
key | string? | The key to sort by, if the array is an array of objects. | |
reverse | boolean | false | whether to reverse the array after sorting. |
{slice;target;start;end}
Get a slice of an array or string. If end
is not specified, it is assumed to be the length of the target.
Name | Type | Description |
---|---|---|
target | string | The array or string to get a slice of. |
start | number | The index to start the slice from. |
end | number? | The index to end the slice at. If not specified, it is assumed to be the length of the array or string. |
{=array;{[one;two;three]}}
{slice;{$array};1} // {[two;three]}
{slice;{$array};1;2} // {[two]}
{index mode;array;value}
Return the index at which a given element can be found in the array. Defaults to the first instance.
Name | Type | Description |
---|---|---|
array | array | The array to index |
value | any | The value to look for |
mode | string? | An option mode for indexing the array. Can be last to get the last matching index or all to get all matching indexes. |
{filter;array;value;operator;key}
Return an array with just the elements that pass a check.
Name | Type | Default | Description |
---|---|---|---|
array | array | The array to filter | |
value | any | The value to filter by | |
operator | string? | The operator to filter by. The available operators are == , === , != , !== , > , >= , < , <= , startswith , endswith , contains , includes , has and matches . | |
key | string? | The key to filter by if the array is an array of objects. If you are filtering an array of objects and want to filter a specific field for a specific value. For example [{name: "Atlas"}, {name: "Gemini"}] |
{splice;array;array...}
Combines two or more arrays into one.
Name | Type | Description |
---|---|---|
array | array | The arrays to combine, can be two or more arrays. |
{=first_array;{[one;two;three]}}
{=second_array;{[four;five;six]}}
{splice;{$first_array};{$second_array}} // {[one;two;three;four;five;six]}