Filters for String Operations with Scriptlets
Scriptlets allow you to easily format strings with filters. You can capitalize words, append text, or even truncate the string.
default
Section titled “default”Output a default, fallback value if the input text is null or blank.
Hello {? {{First Name}} | default: "sir" | append: "," ?}append
Section titled “append”Concatenates two strings and returns the concatenated value.
{? "weekly.report" | append: ".pdf" ?}You can also use dynamic placeholders with scriptlets.
{? "{{File Name}}" | append: ".pdf" ?}prepend
Section titled “prepend”Adds the specified string to the beginning of another string.
{? "{{Country Name}}" | prepend: "They live in " ?}capitalize
Section titled “capitalize”Makes the first character of a string capitalized. For instance, if you have a Google Sheet with names filled in mixed case, the capitalize while filter will make the first letter of each name capitalized.
{? "angus" | capitalize | prepend: "Hello " ?}upcase
Section titled “upcase”Makes each character in a string uppercase. This filter is useful for acronyms filled in lowercase in a form response or a Google Sheet.
{? "unicef” | upcase ?}downcase
Section titled “downcase”Makes each character in a string lowercase
{? "Hello Sir!" | downcase ?}truncate
Section titled “truncate”Shortens a string down to the number of specified characters. If the number of characters is less than the length of the string, the string is returned with ellipsis (…) appended to the end.
{? "His name is Angus McDonald" | truncate: 11 ?}If you would like to use a different ellipsis, you can specify it as the second parameter of the truncate filter. Or use "" if you would not like to append any character to the truncated string.
{? "His name is Angus McDonald" | truncate: 11, "---" ?}truncatewords
Section titled “truncatewords”Shortens a string down to the number of words with ellipsis appended at the end.
{? "The quick brown fox jumped over the lazy dog!" | truncatewords: 5 ?}After the truncate or truncatewords filter, we can specify the text we want to add within inverted commas. If nothing is specified, ellipsis are automatically added.
{? "The quick brown fox jumped over the lazy dog!" | truncatewords: 5, " ...to be continued" ?}{? "The quick brown fox jumped over the lazy dog!" | truncate: 40, " ...to be continued." ?}Returns a substring of ‘n’ character beginning at the index specified by the first argument.
{? "Male" | slice: 0 ?}Please note that index positions of characters are counted starting from zero. In the example below, the letter T is at 0th index position. Hence, the letter q is at 4th index position. The second argument, 11, is the number of characters after the specified index position. Thus, 11 characters are counted starting from the letter q.
{? "The quick brown fox jumped over the lazy dog!" | slice: 4, 11 ?}If the first argument of the slice filter is a negative number, the indices are counted from the end of the string.
{? "The quick brown fox jumped over the lazy dog!" | slice: -9,4 ?}