Five ways of using the path twig function for route links in drupal 8, 9 or 10

Linking to routes in Twig has become much easier since the release of some updates in Drupal 8. Here are 5 snippets that help when linking to internal routes.

Check in twig if image field has value [drupal 8]

In a node teaser or full view mode it is for front-end purposes needed to know if an image is available. This snippet takes care of it.

Get views row count in twig [drupal 8]

When using twig, sometimes you would like to know whether the view has results or not. This snippet shows you how.

Date field formatting in twig in drupal 8

The following snippet makes you format a date field inside a twig file.

Twig snippet to hide region if empty in drupal 8

I encountered this bug in a Display suite 2-column lay-out where I wanted the left region to disappear when empty. 

Subscribe to Twig