Functional template functions
These template functions help with control flow, conditional logic, and general utility operations. They let you make decisions, transform values, and work with data in flexible ways.
Home Assistant extends the Jinja2 template engine with many custom functions, filters, and tests. Each function on this page has its own page with detailed descriptions, parameters, and practical examples.
New to templates? Start with the templating documentation to learn the basics.
-
Call a function dynamically
applyCalls a function with a value, letting you pass any function into places where a filter is expected. -
Turn a macro into a function
as_functionTurns a template macro into a reusable function you can pass to map, select, and reject. -
Check if value another
containsTests if a value contains another value. Works with strings, lists, and dictionaries. -
Cycle through values
cyclerCreates an object that cycles through a list of values. Useful for alternating between values in a loop. -
Create a ionary
dictCreates a dictionary from keyword arguments. -
Immediate if (ternary)
iifShorthand for basic if/else logic in a single expression. -
Join loop iterations
joinerCreates a helper that joins loop iterations with a separator, returning an empty string on the first call. -
Generate placeholder text
lipsumGenerates lorem ipsum placeholder text. Useful for testing and prototyping templates. -
Create a mutable
namespaceCreates a mutable namespace object for storing variables across loop scopes in templates. -
Unicode code point
ordReturns the Unicode code point for a single character. -
Choose a value
randomChooses a random value from a list. Returns a different value each time the template is evaluated. -
Generate a number sequence
rangeGenerates a sequence of numbers, like Python's range(). Commonly used for looping a specific number of times. -
Parse a string
versionConverts a string into a version object that supports comparison operators. -
Combine iterables
zipZips multiple iterables together into a list of tuples, pairing elements by position.