Jinja Variables
jinja_variables is an object to declare variables intended to be used inside Jinja templates. This object can store string, number, and boolean variables as well as dictionaries (or objects) and lists (or arrays). These variables will be available in any partial or in any template.
Important
jinja_variablesonly allowsstring,numberandbooleanvariables as well asdictionariesandlistscontaining otherdictionariesorlistsor the aforementioned primitives. Trying to send other kinds of variables will end in an error.jinja_variablesdon't compile any template string. So if you set a variable as a template string, it will be interpreted as a string and a warning will be thrown in the console.
Example
The next example will set "Title 80 dog" as the title of the page:
- YAML
- JSON
<config directory>/www/sidebar-config.yaml
jinja_variables:
my_string: Title
my_number: 100
my_boolean: true
my_dictionary:
prop1: 4
prop2: 5
my_list:
- cat
- dog
- bird
title: |
{% if my_boolean %}
{{ my_string }} {{ ((my_number * my_dictionary.prop1) / my_dictionary.prop2) | int }} {{ my_list.1 }}
{% else %}
Home Assistant
{% endif %}
<config directory>/www/sidebar-config.json
{
"jinja_variables": {
"my_string": "Title",
"my_number": 100,
"my_boolean": true,
"my_dictionary": {
"prop1": 4,
"prop2": 5
},
"my_list": [
"cat",
"dog",
"bird"
]
},
"title": "{% if my_boolean %} {{ my_string }} {{ ((my_number * my_dictionary.prop1) / my_dictionary.prop2) | int }} {{ my_list.1 }} {% else %} Home Assistant {% endif %}"
}