String functions
capitalize
capitalize(): str
Capitalizes the first letter of a string
Input example
<b>{{ "hello, world!".capitalize() }}</b>
Output
<b>Hello, world!</b>
contains
contains(substr: str): bool
Returns true if the string contains the given substring, otherwise false. The function is sase-sensitive, so the substring must match the case of the string
Arguments
substr
(str) - The substring to search for
Input example
<b>{{ "Hello, World!".contains("World") }}</b>
Output
<b>true</b>
If the substr
argument is an empty string, the function will always return true
. It's done this way because an empty string is always a substring of any string
len
len(): int
Returns the length of the string
Input example
<b>{{ "Hello, World!".len() }}</b>
Output
<b>13</b>
lower
lower(): str
Converts a string to lowercase
Input example
<span>{{ "Hello, World!".lower() }}<span>
Output
<span>hello, world!</span>
raw
raw(): str
Function raw
is used to render a string as raw HTML. This is useful when you want to render HTML tags from a string. By default, HTML tags in a string are escaped to prevent XSS attacks
Input example
{{ "<h1>Test</h1>".raw() }}
Output
<h1>Test</h1>
reverse
reverse(): str
Returns a string with the characters reversed
Input example
<b>{{ "stressed".reverse() }}</b>
Output
<b>desserts</b>
split
split(separator?: str = " "): arr
Function split
is used to split a string into an array of substrings. It takes an optional argument separator
which is used to split the string. If no separator is provided, it defaults to a space
Arguments
separator
(str) (optional) - What separator to use to split the string. Default is " " (space)
Input example
<div>{{ "one two".split(" ") }}</div>
Output
<div>one, two</div>
trim
trim(chars?: str = "\t \n\r"): str
Trims a string from spaces and special characters like tabs, spaces and new lines by default. You can pass a argument to trim a specific set of characters from a string
Arguments
chars
(str) (optional) - A string of characters to trim from a string. Default is\t \n\r
Input example
<span>{{ " Anna ".trim() }}</span>
Output
<span>Anna</span>
upper
upper(): str
Converts a string to uppercase
Input example
<b>{{ "Hello, World!".upper() }}</b>
Output
<b>HELLO, WORLD!</b>