Skip to content

Commit 4998875

Browse files
committed
Move {% raw %}
1 parent 586ea56 commit 4998875

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

source/_docs/automation/templating.markdown

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ In Home Assistant 0.19 we introduced a new powerful feature: variables in script
1414

1515
The trigger data made is available during [template](/docs/configuration/templating/) rendering as the `trigger` variable.
1616

17+
{% raw %}
1718
```yaml
1819
# Example configuration.yaml entries
1920
automation:
@@ -23,28 +24,29 @@ automation:
2324
action:
2425
service: notify.notify
2526
data_template:
26-
message: >{% raw %}
27+
message: >
2728
Paulus just changed from {{ trigger.from_state.state }}
28-
to {{ trigger.to_state.state }}{% endraw %}
29+
to {{ trigger.to_state.state }}
2930
3031
automation 2:
3132
trigger:
3233
platform: mqtt
3334
topic: /notify/+
3435
action:
35-
service_template: >{% raw %}
36-
notify.{{ trigger.topic.split('/')[-1] }}{% endraw %}
36+
service_template: >
37+
notify.{{ trigger.topic.split('/')[-1] }}
3738
data_template:
38-
message: {% raw %}'{{ trigger.payload }}'{% endraw %}
39+
message: '{{ trigger.payload }}'
3940
```
41+
{% endraw %}
4042
4143
## {% linkable_title Important Template Rules %}
4244
4345
There are a few very important rules to remember when writing automation templates:
4446
45-
1. You ***must*** use `data_template` in place of `data` when using templates in the `data` section of a service call.
46-
1. You ***must*** use `service_template` in place of `service` when using templates in the `service` section of a service call.
47-
1. You ***must*** surround single-line templates with double quotes (`"`) or single quotes (`'`).
47+
1. You **must** use `data_template` in place of `data` when using templates in the `data` section of a service call.
48+
1. You **must** use `service_template` in place of `service` when using templates in the `service` section of a service call.
49+
1. You **must** surround single-line templates with double quotes (`"`) or single quotes (`'`).
4850
1. It is advised that you prepare for undefined variables by using `if ... is not none` or the [`default` filter](http://jinja.pocoo.org/docs/dev/templates/#default), or both.
4951
1. It is advised that when comparing numbers, you convert the number(s) to a [`float`](http://jinja.pocoo.org/docs/dev/templates/#float) or an [`int`](http://jinja.pocoo.org/docs/dev/templates/#int) by using the respective [filter](http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters).
5052
1. While the [`float`](http://jinja.pocoo.org/docs/dev/templates/#float) and [`int`](http://jinja.pocoo.org/docs/dev/templates/#int) filters do allow a default fallback value if the conversion is unsuccessful, they do not provide the ability to catch undefined variables.

0 commit comments

Comments
 (0)