Drupal 8 twig snippets

Ternary operator ​​​​​

{% set foo = true %}
{{ foo ? 'FOO IS TRUE' : 'FOO NOT TRUE' }}

If then else

{% if node.getType == 'photo' %}
...
{% elseif node.getType in ['book', 'page'] %}
...
{% else %}
...
{% endif %}

Misc

{{ $uri = path('entity.node.canonical', {'node': node.id}) }}
{% if '/services/' in url %}
{% if uri starts with '/hismb' %}
{% if node.getType == 'photo' %} 
{% if node.getType not in ['text', 'misc' ] %}
{% if not page %}
{% if page %}

Date ranges

{% set yearStart = field_event_date_1__value|date("Y") %}
{% set yearFinish = field_event_date_1__end_value|date("Y") %}
{% set decadeFinish = '/' ~ field_event_date_1__end_value|date("y") %}
{{ field_event_date_1__value|date("Y")  }}{{ yearStart == yearFinish ? '' : decadeFinish }}

Tuesday, May 19, 2020 - Thursday, May 21, 2020 or Wednesday, May 13, 2020

{% set start = field_date__value|date("l, F j, Y") %}
{% set finish = field_date__end_value|date("l, F j, Y") %}
{% if start == finish %}
{{ start }}
{% else %}
{{ start }} - {{ finish }}
{% endif %}