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 }}