Formatting for multi-line templates - angle bracket usage

Apologies if this is covered somewhere in the docs, but I think I have seen examples both ways. What is the difference between “>” and “>-” when templating? e.g.

    # Angle bracket alone
    value_template: >
      {% if is_state_attr('remote.living_room_harmony', 'current_activity', 'PowerOff') %}
        off
      {% else %}
        on
      {% endif %}

versus

    # Angle bracket with dash
    value_template: >-
      {% if is_state_attr('remote.living_room_harmony', 'current_activity', 'PowerOff') %}
        off
      {% else %}
        on
      {% endif %}

See:

https://yaml-multiline.info/

And in the case you show, absolutely nothing.

2 Likes

That is interesting. It seems to be saying there is a difference between ’ (single quotes) and " (double quotes) in some circumstances.

Also is this a page all on it’s own? I was wondering if it were one page of series of other similarly helpful pages?

It’s just saying that if a string is quoted, how you escape a quote inside the string depends on which type of quote you used to quote the entire string. If you quote a string with single quote characters, then you don’t need to escape double quote characters inside the string, and you escape single quote characters by using two in a row (''). Whereas if you quote a string with double quote characters, then you don’t need to escape single quote characters inside the string, and you escape double quote characters by preceding them with a backslash (\").

No idea. Someone pointed out this link which has helped me in the past, so I thought I’d share it.

2 Likes

Great, that makes sense. Thanks for the link.