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

Drupal 8 add classes to body using URL

https://www.heididev.com/add-class-body-based-path-alias-drupal-8

Turn on twig debug.

Locate view template in use.

In my case, they were in

profiles/cms/themes/contrib/bootstrap/templates/views

In views-view.html.twig I found the div containing the views-content class.

Adding "container" to views-content and to views-header allowed a full-width content section to behave with expected margin yet have full width background image.

 

Pages

Subscribe to Front page feed