Skip to content

Commit b42f23d

Browse files
committed
Add quote explanation and examples
1 parent 3f13571 commit b42f23d

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

source/developers/documentation/standards.markdown

+54-4
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ To ensure that the documentation for Home Assistant is consistent and easy to fo
2525
* Configuration variables must document the requirement status.
2626
* Configuration variables must document the default value, if any.
2727
* Configuration variables must document the accepted value types.
28-
* Use `[string, int]` for configuration variables that accept multiple types.
28+
* For configuration variables that accept multiple types, separate the types with a comma (i.e. `string, int`).
2929
* Use YAML sequence syntax in the sample code if it is supported.
3030
* All examples should be formatted to be included in `configuration.yaml` unless explicitly stated.
3131
* Use capital letters and `_` to indicate that the value needs to be replaced. E.g., `api_key: YOUR_API_KEY` or `api_key: REPLACE_ME`.
32-
* If you know that the API key or value contains [control characters](https://en.wikipedia.org/wiki/YAML#Syntax), e.g., `#`, `[`, `?`, etc., wrap it in quotes and add a note.
32+
* If you know that the API key or value contains [control characters](https://en.wikipedia.org/wiki/YAML#Syntax), e.g., `#`, `[`, `?`, etc., wrap it in quotes and add a note.
3333
* Component and platform names should be a link to their respective documentation pages.
3434

3535
## {% linkable_title Templates %}
3636

3737
* All examples containing Jinja2 templates should be wrapped **outside** of the code markdown with the {% raw %}`{% raw %}`{% endraw %} tag.
3838
* Do not use `states.switch.source.state` in templates. Instead use `states()` and `is_state()`.
39-
* Use double quotes (`"`) for:
39+
* Use double quotes (`"`) for ([more information](#single-vs-double-quotation-marks)):
4040
* `friendly_name`
4141
* Single-line templates:
4242
* `value_template`
4343
* `level_template`
4444
* `icon_template`
4545
* Children of `data_template`
46-
* Use single quotes (`'`) for:
46+
* Use single quotes (`'`) for ([more information](#single-vs-double-quotation-marks):
4747
* Strings inside of templates:
4848
* States
4949
* Entity IDs
@@ -69,3 +69,53 @@ redirect_from: /getting-started/android/
6969
```
7070

7171
Adding a redirect also applies if you move content around in the [documentation](/docs/).
72+
73+
## {% linkable_title Single vs. Double Quotation Marks %}
74+
75+
Use single quotes (`'`) for strings inside of a template. It is more obvious to escape a single quote when necessary (i.e. `name` is a possessive noun), because the single quotes that wrap the string are closer in position to the apostrophe inside the string. Use double quotes (`"`) outside of a template (unless it is a multi-line template, in which case outside quotes are not required).
76+
77+
### {% linkable_title Examples %}
78+
79+
#### {% linkable_title Double Quotes Outside, Single Quotes Inside (Valid) %}
80+
81+
{% raw %}
82+
```yaml
83+
automation:
84+
...
85+
action:
86+
- service: notify.notify
87+
data_template:
88+
message: "{% if trigger.to_state.name == 'Dale\'s Bedroom' %}Someone's in your base, killing your noobs!{% else %}It's just another door.{% endif %}"
89+
```
90+
{% endraw %}
91+
92+
#### {% linkable_title Single Quotes Outside, Double Quotes Inside (Invalid) %}
93+
94+
{% raw %}
95+
```yaml
96+
automation:
97+
...
98+
action:
99+
- service: notify.notify
100+
data_template:
101+
message: '{% if trigger.to_state.name == "Dale's Bedroom" %}Someone's in your base, killing your noobs!{% else %}It's just another door.{% endif %}'
102+
```
103+
{% endraw %}
104+
105+
#### {% linkable_title Multi-Line Template (Valid) %}
106+
107+
{% raw %}
108+
```yaml
109+
automation:
110+
...
111+
action:
112+
- service: notify.notify
113+
data_template:
114+
message: >-
115+
{% if trigger.to_state.name == 'Dale\'s Bedroom' %}
116+
Someone's in your base, killing your noobs!
117+
{% else %}
118+
It's just another door.
119+
{% endif %}
120+
```
121+
{% endraw %}

0 commit comments

Comments
 (0)