Functions on Data Types

To empower you in working with your variables Jinja allows you to pick out certain properties of the stored values by functions. Even though Jinja is written in Python. However, given Jinja's sandboxing capabilities, the Jinja data types do not behave the same way as in Python. Therefore, this document explains which functions are present in Bloomreach Engagement's Jinja configuration.

Integer

int.bit_length()
Returns the number of bits necessary to represent an integer in binary, excluding the sign and leading zeros. See Python int.bit_length() reference.

int.conjugate()
Returns the conjugate of the complex number.
Complex numbers are not supported, so int.conjugate() returns the number itself.

Float

float.as_integer_ratio()
Returns a tuple containing a pair of integers whose ratio is exactly equal to the original float and with a positive denominator.

float.as_integer_ratio() throws error on infinities and on NaNs.

float.is_integer()
Returns True if the float instance is finite with integral value, and False otherwise.

float.hex()
Returns a representation of a floating-point number as a hexadecimal string. For finite floating-point numbers, this representation will always include a leading 0x and a trailing p and exponent. See the Python float.fromhex() reference.

float.fromhex(string)
Returns float represented by a hexadecimal string. The string may have leading and trailing whitespace. See the Python float.fromhex() reference.

float.conjugate()
Returns the conjugate of the complex number. Complex numbers are not supported, so int.conjugate() returns the number itself.

String

str.capitalize()

Returns a copy of the string with its first character capitalized and the rest lowercase.

str.center(width[, fillchar])

Returns a centered string of length width. Padding is done using the specified fillchar (default is an ASCII space). The original string is returned if the width is less than or equal to len(s). Similar to str.ljust() and str.rjust().

str.count(sub[, start[, end]])

Returns the number of non-overlapping occurrences of substring sub in the range [start, end]. Optional arguments start and end are interpreted as in slice notation.

str.encode(encoding="utf-8", errors="strict")

Returns an encoded version of the string as a bytes object. Default encoding is 'utf-8'. errors may be given to set a different error handling scheme.

str.endswith(suffix[, start[, end]])

Returns True if the string ends with the specified suffix, otherwise return False. the suffix can also be a tuple of suffixes to look for. With optional start, test beginning at that position. With optional end, stop comparing at that position.

str.expandtabs(tabsize=8)

Returns a copy of the string where all tab characters are replaced by one or more spaces, depending on the current column and the given tab size. sub[, start[, end]]

str.find(sub[, start[, end]])

Returns the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if a sub is not found.

str.index(sub[, start[, end]])

Like str.find(), but throws an error when the substring is not found. Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation.

str.isalnum()

Returns true if all characters in the string are alphanumeric and there is at least one character, false otherwise.

str.isalpha()

Returns true if all characters in the string are alphabetic and there is at least one character, false otherwise.

str.isdigit()

Returns true if all characters in the string are digits and there is at least one character, false otherwise.

str.islower()

Returns true if all cased characters in the string are lowercase and there is at least one cased character, false otherwise.

str.isspace()

Returns true if there are only whitespace characters in the string and there is at least one character, false otherwise.

str.istitle()

Returns true if the string is a title cased string and there is at least one character. For example, uppercase characters may only follow uncased characters and lowercase characters only cased ones. Return false otherwise.

str.isupper()

Returns true if all cased characters in the string are uppercase and there is at least one cased character, false otherwise.

str.join(iterable)

Returns items of the iterable joined by the string. An error will be thrown if there are any non-string values in iterable. The separator between elements is the string providing this method.

str.ljust(width[, fillchar])

Returns the string justified to the left by adding fillchar character to the right, so that the string + filling characters have a length of the specified width. Padding is done using the specified fillchar (default is an ASCII space). The original string is returned if the width is less than or equal to the string length. Similar to str.center() and str.rjust().

str.lower()

Returns a copy of the string with all the cased characters converted to lowercase.

str.lstrip([chars])

Returns a copy of the string with leading characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix; rather, all combinations of its values are stripped. Similar to str.strip() and str.rstrip().

str.partition(sep)

Split the string at the first occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing the string itself, followed by two empty strings.

str.replace(old, new[, count])

Returns a copy of the string with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.

str.rfind(sub[, start[, end]])

Returns the highest index in the string where substring sub is found, such that sub is contained within s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

str.rindex(sub[, start[, end]])

Like str.rfind() but throws an error when the substring sub is not found.

str.rjust(width[, fillchar])

Returns the string right-justified in a string of length width. Padding is done using the specified fillchar (default is an ASCII space). The original string is returned if the width is less than or equal to len(s). Similar to str.center() and str.ljust().

str.rpartition(sep)

Splits the string at the last occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing two empty strings, followed by the string itself.

str.rstrip([chars]))

Returns a copy of the string with trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a suffix; rather, all combinations of its values are stripped. Similar to str.lstrip() and str.strip().

str.split(sep=None, maxsplit=-1)

Returns a list of the strings split by the separator sep. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified or -1, then there is no limit on the number of splits. Splitting an empty string with a specified separator returns [''].

If sep is not specified or is None, the string is split at whitespace (multiple consecutive whitespace characters are regarded as a single splitting region). The result will contain no empty strings at the start or end of the string that has leading or trailing whitespace.

str.splitlines()

Returns a list of the lines in the string, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true. See Python str.splitlines() reference to see which characters are split.

str.startswith(prefix[, start[, end]])

Returns True if the string starts with the prefix, otherwise return False. the prefix can also be a tuple of prefixes to look for. With optional start, test string beginning at that position. With optional end, stop comparing string at that position.

str.strip([chars])

Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped. Similar to str.lstrip() and str.strip().

str.swapcase()

Returns a copy of the string with uppercase characters converted to lowercase and vice versa.

str.title()

Returns a title cased version of the string where words start with an uppercase character and the remaining characters are lowercase.

str.translate(table)

Returns a copy of the string in which each character has been mapped through the given translation table.

Although this method is available, str.maketrans(), which is used to create translation tables, is not. Therefore, there is no use for str.translate() currently.

str.upper()

Returns a copy of the string with all the cased characters converted to uppercase.

str.zfill(width)

Returns a copy of the string left filled with ASCII '0' digits to make a string of length width. A leading sign prefix ('+'/'-') is handled by inserting the padding after the sign character rather than before. The original string is returned if the width is less than or equal to len(s). Similar to str.rjust().

List

list.count(item)

Returns the number of occurrences of the given item in the List.

list.index(item[, start[, end]])

Returns the lowest index in the List where the given item is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Similar to str.index().
list.index() throws an error if index not within the List.

list.pop([index])

Returns the item at index position in List and also removes it from the List. If no index provided, returns and removes the last item in the list. list.pop() throws an error if index not within the List.

Tuple

tuple.count(item)

Returns the number of occurrences of the given item in the Tuple.

tuple.index(item[, start[, end]])

Returns the lowest index in the Tuple where the given item is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Similar to str.index(). tuple.index() throws an error if index not within the List.

Dictionary

dict.fromkeys(seq[, value])

Creates a new dictionary with keys from seq and all values set to value. value defaults to None.

dict.get(key[, default])

Returns the value for key if the key is in the dictionary, else default. If a default value is not given, it defaults to None.

dict.items()

Returns a List of Tuples of (key, value).