Skip to main content

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​

Output a default, fallback value if the input text is null or blank.

Hello {? {{First Name}} | default: "sir" | append: "," ?}
// Output: Hello sir, or Hello <name>, if name is provided

append​

Concatenates two strings and returns the concatenated value.

{? "weekly.report" | append: ".pdf" ?}
// Output: weekly.report.pdf

You can also use dynamic placeholders with scriptlets.

{? "{{File Name}}" | append: ".pdf" ?}
// Output: report.pdf

prepend​

Adds the specified string to the beginning of another string.

{? "{{Country Name}}" | prepend: "They live in " ?}
// Output: They live in India

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 " ?}
// Output: Hello Angus

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 ?}
// Output: UNICEF

downcase​

Makes each character in a string lowercase

{? "Hello Sir!" | downcase ?}

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 ?}
// Output: His name...

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, "---" ?}
// Output: His name---

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 ?}
The quick brown fox jumped…

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" ?}
// Output: The quick brown fox jumped ...to be continued

{? "The quick brown fox jumped over the lazy dog!" | truncate: 40, " ...to be continued." ?}
// Output: The quick brown fox ...to be continued.

slice​

Returns a substring of 'n' character beginning at the index specified by the first argument.

{? "Male" | slice: 0 ?}
// Output: M

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 ?}
// Output: quick brown

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 ?}
// Output: lazy