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: install an existing Drupal site on Lando

This tutorial explains how to install an existing Drupal 9 website locally with Lando.

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

How to loop over config file values in Drupal

I had this use case in my theme, where I wanted to expose a bunch of settings to my page.html.twig. Typical things would be social media links. Here is how I looped over config file values, preventing me to write a lot of lines:

Subscribe to Drupal