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:

Drupal Behaviors: A How-To Guide to Javascript

Writing JavaScript code in Drupal can be challenging because of the way Drupal handles JavaScript. Drupal has a concept called "Drupal behaviors" that can help you write better JavaScript code that works consistently across your site.

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

Get url path of an entity reference in Twig in Drupal 10

This post gives you a snippet to get the URL path of an entity reference in Twig

Get page title inside of a paragraph in Drupal 10

I encountered this when I had to build a hero paragraph. I needed the page title inside my paragraph.

How to access custom block content field in Twig (Drupal 10)

I started using custom blocks for reusable content on a website. It turns out twig works a bit different on block content than on paragraphs.

How to loop over field items in twig file in Drupal

If you want to use a looping functionality in x.html.twig​​​​​​​ you can use the following:

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:

Subscribe to Drupal theming