How to add direct share links to your Drupal page in page.html.twig

The following snippets can be used to get direct share links to Facebook, Twitter and LinkedIn in your page.html.twig

Get a link field url and value in Twig for both internal and external links

Drupal's link field is quite generic. You can both add internal paths as external links. Here is how get the correct values in twig.

How to know if a user is logged in in page.html.twig in Drupal

This is quite an easy one. You get the following variables available in page.html.twig:

How to get entity reference value and link to it in a paragraph

I had this use case where I had to show a label and link to another content type from within my paragraph. Because the theming was specific, I had to get the label and link in twig

How to do a for loop in Twig PHP

This is the way to do a "for" loop. We are going to loop over an array of Node objects of type 'sector'

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