These filters may be used on multiple object types with different results.
any defaultValue
If the current value is null, an empty string, or invalid (object.is_valid == false), return the default_value. Otherwise return the original value.
Example: default string
Example: default number
string format
Returns the object formatted as a string using the provided format string. There are three types of objects that can be formatted, and each type uses its own format strings:
Require a valid standard or custom .NET numeric format string. This is identical to using the format_number filter on a number.
Example: format numbers
Require a valid standard or custom .NET date format.
Example: format dates
Require a valid standard or custom.NET TimeSpan format.
Example: format time diffs
If the input object is a string that can be converted to a date, it will be converted to a date before formatting. Otherwise if the input is a string that can be converted to a number, it will be converted to a number before formatting.
integer maxDepth = 10 boolean forceLoad = false
Returns a json-like representation of the current object up to maxDepth layers deep (max 10). Will not load new information from the server unless forceLoad is set to true. Useful during template development and debugging, but do not rely on the result of the inspect tag for your live site.
Example: debug an unknown field
boolean genericObjectCheck = false
Returns a string identifying the type of the input object. If genericObjectCheck is true, will return "object" for most objects. If genericObjectCheck is false or unspecified, will return the value of {{ object.object_type }} for objects with an object_type property. The most common values are:
Example: output the type of an unknown variable
integer length = 1 boolean allowRepeats = true boolean preventCache = true
Behaves differently depending on the arguments supplied. Unless preventCache is false, the rand filter will prevent the page from being fast-cached. Note: the rand filter should NOT be considered cryptographically secure - do not use in places where cryptographic security is a requirement (ie: do not use to generate random passwords).
If the input is an integer and length is 1, returns a new integer between 1 and the input value. If the input is an integer and length is greater than 1, returns a new list of length numbers between 1 and the input value. If allowRepeats is false, the list returned will be unique. This may result in a list with fewer than length items if the input is less than length.
Example: Get a random number between 1 and 10
Example: Get a random number between 0 and 10
Example: Get 4 random numbers between 1 and 10
Example: Get 4 unique random numbers between 1 and 10
If the input is a string, returns a new random string with length characters, where each character comes directly from the input. If allowRepeats is false, no characters from the input will be used more than once (although any character repeated in the input may be repeated up to the same number of times in the resulting string) - which may result in a string shorter than length if the input string is shorter than length.
Example: Get a random character from a string
Example: Generate a random alphanumeric string 10 characters long
If the input is a list or list-like object and length is 1, returns a random object from the list. If the input is a list or list-like object and length is greater than 1, returns a new random list of length items from the input list. If allowRepeats is false, no items from the input will be used more than once (although any repeated items in the input may be repeated up to the same number of times in the resulting list) - which may result in a list with fewer than length items if the input list has fewer than length items.
Example: Get a random blog post from a list of blog posts
Example: Get 3 random blog posts from a list of blog posts
Converts the input to true or false if possible. If not returns null.
Example: Convert to boolean