Twig

Blog

Access the parent paragraph inside child paragraph with Twig in Drupal

Sometimes you need to know inside which parent paragraph the current paragraph you are working in is. Here is how to do it in Twig.

Blog

How to get the path of an uploaded file inside a Twig template in Drupal 10

In this blog post, we will explore how to get the path of an uploaded file inside a Twig template in Drupal 10.

Blog

How to Fetch and Display the Label of a List Field in a Twig Template (Drupal 10)

In this post, we will explore some of the most effective methods to help you display the label of a list field in your Twig template.

Blog

How to Use the Ternary Operator in Twig in Drupal 10

In Drupal 10, you can use the ternary operator in the same way as in regular Twig code. Here's an example of how you can use the ternary operator to create an array of CSS class names based on some conditions:

Blog

Get url path of referenced node image in Twig and Drupal 10

This snippet will definitely save you some time searching for the proper structure, it loops over entity referenced nodes and sets a background image from that node

Blog

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

Blog

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.

Blog

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:

Blog

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

Blog

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'

Subscribe to Twig