When building Looping Blocks that use EDP as the data source, the platform supports the following Global Helpers for the Looping Block Handlebars code.
This helper formats the field as a number. This syntax for this helper is {{addCommas fieldname}}. In the below example, the block will output "1,000,000" when the value in "large_number" is "1000000."
{{addCommas large_number}}
This helper base64-encodes a text string. The syntax for this helper is {{base64 fieldname}}. In the below example, the block will output "dGVzdEB0ZXN0LmNvbQ==" when the value in "email" is "test@test.com."
{{base64 email}}
This helper capitalizes the first word in a sentence. This helper uses the syntax {{Capitalize fieldname}}. In the below example, the block will output "John" when given the firstName value "john."
{{Capitalize firstName}}
This helper compares two values using a mathematical operator. If the comparison resolves to true, the block will output the provided content; optionally, if the comparison resolves to false, the block will output the inverse content. If you don't specify the inverse content, and the comparison resolves to false, nothing is displayed. The syntax for this helper is:
{{#compare fieldname operator value}}
block content
{{else}}
inverse block content
{{/compare}}
"Fieldname" is the name of the field to compare, "operator" is a mathematical operator (see below for valid options), and "value" is the argument against which to compare. "Value" can be another field, or it can be an explicit value. If using another field, the field name should not be enclosed in quotes. If using an explicit value, the value should be enclosed in quotes.
The value for "operator" must be enclosed in quotes. The valid values for "operator" are
"="
"!="
"<"
">"
"<="
">="
This helper formats the field as a date. The syntax for this helper is {{dateFormat fieldname format='date format'}}. In the below example, the block will output "02/12/1985" when the value in "birthdate" is "120285."
{{dateFormat birthdate format="DD/MM/YYYY"}}
This helper displays a default if the given value evaluates to false. The syntax for this helper is {{default fieldname "default value"}}, where "fieldname" is the attribute, and "default value" is the text to display if the attribute is false. In the below example, the block will display "Valued Customer" if the value of "firstname" is empty.
{{default firstname "Valued Customer" }}
Note: The Default value helper also supports using a formatter as well. For example, if you wanted to Capitalize and use a Default value, you would use {{capitalize (default fieldname "default value")}}
This helper displays the first N values in an array. The syntax for this helper is {{first fieldname X "separator"}}, where "fieldname" is the attribute, "X" is the number of values to display, and "separator" is the character or divider to put between the returned values, such as a space, a comma, or a line break (<br/>) . "X" is optional; if "X" is not specified, the block will return the first value only. "Separator" is also optional; if "separator" is not defined, the block will default to ", " (comma space). Consider the following example:
{{first items 3 ", "}}
Given the items "brush, comb, elastic, spray," the block will display: "brush, comb, elastic."
This helper looks for a specified value within an array. If the value is found, the block will output the provided content; optionally, if the value is not found, the block will output the inverse content. If you don't specify the inverse content, and the specified value is not found within the array, nothing is displayed. The syntax for this helper is:
{{#inArray fieldname value}}
block content
{{else}}
inverse block content
{{/inArray}}
"Fieldname" is the name of the array field to interrogate, and "value" is the value to look for within the array.
This helper displays the value at a specific position. The syntax for this helper is {{itemAt fieldname X}}, where "fieldname" is the attribute, and "X" is the position of the value to display (using a 0 index). Consider the following example:
{{itemAt items 2}}
When given the items "brush, comb, elastic, spray," the block will display: "elastic."
This helper displays the last N values in an array. The syntax for this helper is {{last fieldname X "separator"}}, where "fieldname" is the attribute, "X" is the number of values to display, and "separator" is the character or divider to put between the returned values, such as a space, a comma, or a line break (<br/>) . "X" is optional; if "X" is not specified, the block will return the last value only. "Separator" is also optional; if "separator" is not defined, the block will default to ", " (comma space). Consider the following example:
{{last items 3 "<br/>"}}
Given the items "brush, comb, elastic, spray," the block will display:
comb
elastic
spray
This helper will enable a user to replace specific values in a given array with something else. The syntax for this helper is {{replace fieldname "oldvalue" "newvalue"}} where "fieldname" is the name of the field containing the array, "oldvalue" is the value in the field to be replaced, and "newvalue" is the value being used to replace "oldvalue." In the below example, the block will output "a,z,c,d" when the value in "letters" is "a,b,c,d."
{{replace letters "b" "z"}}
This helper sorts the values alphanumerically in ascending or descending order. The helper supports sorting by only one property. The syntax for this helper is {{sortBy fieldname direction "separator"}}, where "fieldname" is the attribute, "direction" is either ascending ("ASC") or descending ("DESC") sort sequence, and "separator" is the character or divider to put between the returned values, such as a space, a comma, or a line break (<br/>) . "Order" is optional; if not defined, the order will be ascending. "Separator" is also optional; if "separator" is not defined, the block will default to ", " (comma space). In the below example, the block would sort the array in "items" in descending order, with a comma between each value.
{{sortBy items DESC ","}}
This helper sums all the numbers in the given array. The syntax for this helper is {{sum fieldname}}. In the below example, the block will output "10" when the value in "numbers" is "1,2,3,4."
{{sum numbers}}
This helper will de-duplicate the values in an array and return only the unique values. This helper is typically used in conjunction with the "each" helper. The syntax for this helper is {{#each (unique fieldname)}}, where "fieldname" is the field containing the array that you want to de-duplicate. Consider the following example:
{{#each (unique testarray)}}
Given a "testarray" value of 'a', 'a', 'c', 'b', 'e', 'e', the helper would output: "acbe."
This helper URL-encodes the value of a field. This helper uses the syntax {{url_encode fieldname}}. In the below example, the block will output "%2fHome%2fAbout" where the value of "homepage" is: "/Home/About".
{{url_encode homepage}}