Skip to main content
TemplateDX provides a set of built-in filters that you can use to manipulate and transform data within your templates. Filters are functions that take an input value and return a transformed output.

Built-in Filters

abs

The abs filter returns the absolute value of a number. Syntax
abs(number_value)
Parameters
  • number_value (number): The input number.
Example
abs(-42)
Output:
42

capitalize

The capitalize filter capitalizes the first character of a string. Syntax
capitalize(string_value)
Parameters
  • string_value (string): The input string to be capitalized.
Example
capitalize("hello world")
Output:
Hello world

dump

The dump filter serializes a JavaScript object into a JSON string. Syntax
dump(object_value)
Parameters
  • object_value (any): The input object to be serialized.
Example
dump({ name: "TemplateDX", version: "1.0" })
Output:
{"name":"TemplateDX","version":"1.0"}

join

The join filter joins elements of an array into a single string, separated by a specified separator. Syntax
join(array_value, separator)
Parameters
  • array_value (any[]): The input array.
  • separator (string, optional): The string to separate the array elements. Defaults to ", ".
Example
join(["apple", "banana", "cherry"], ", ")
Output:
apple, banana, cherry

lower

The lower filter converts a string to lowercase letters. Syntax
lower(string_value)
Parameters
  • string_value (string): The input string to be converted to lowercase.
Example
lower("HELLO WORLD")
Output:
hello world

replace

The replace filter replaces all occurrences of a specified substring with a new substring. Syntax
replace(string_value, search, replace)
Parameters
  • string_value (string): The input string.
  • search (string): The substring to search for.
  • replace (string): The substring to replace with.
Example
replace("Hello World", "World", "TemplateDX")
Output:
Hello TemplateDX

round

The round filter rounds a number to a specified number of decimal places. Syntax
round(number_value, decimals)
Parameters
  • number_value (number): The input number to be rounded.
  • decimals (number, optional): The number of decimal places to round to. Defaults to 0.
Example
round(3.14159, 2)
Output:
3.14

truncate

The truncate filter truncates a string to a specified length and appends an ellipsis (...) if necessary. Syntax
truncate(string_value, length)
Parameters
  • string_value (string): The input string to be truncated.
  • length (number): The maximum length of the output string.
Example
truncate("The quick brown fox jumps over the lazy dog", 20)
Output:
The quick brown fo...

upper

The upper filter converts a string to uppercase letters. Syntax
upper(string_value)
Parameters
  • string_value (string): The input string to be converted to uppercase.
Example
upper("hello world")
Output:
HELLO WORLD

urlencode

The urlencode filter encodes a string to be safe for use in URLs. Syntax
urlencode(string_value)
Parameters
  • string_value (string): The input string to be URL-encoded.
Example
urlencode("Hello World!")
Output:
Hello%20World%21