diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index a62643977127..466c4ddcb34d 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -64,6 +64,7 @@ To improve the experience of writing Jinja templates, we have enabled the follow extensions: * [Loop Controls](https://jinja.palletsprojects.com/en/3.0.x/extensions/#loop-controls) (`break` and `continue`) +* [Expression Statements](https://jinja.palletsprojects.com/en/3.0.x/templates/#expression-statement) (`do`) ## Home Assistant template extensions @@ -991,6 +992,21 @@ To evaluate a response, go to **{% my developer_template title="Developer Tools {% endraw %} +### Mutable dictionaries and lists + +- Filter `as_mutable` takes a list or dictionary and returns a mutable copy that you can modify using the standard Python methods and the [`do` syntax](https://jinja.palletsprojects.com/en/3.0.x/templates/#expression-statement). + +For example: + +{% raw %} + +```text +{% set dict = {} | as_mutable %} +{% do dict.update({"key": "value"}) %} {# dict now contains key->value #} +``` + +{% endraw %} + ### Using templates with the MQTT integration The [MQTT integration](/integrations/mqtt/) relies heavily on templates. Templates are used to transform incoming payloads (value templates) to status updates or incoming service calls (command templates) to payloads that configure the MQTT device.