Book Image

Modernizing Drupal 10 Theme Development

By : Luca Lusso
4 (1)
Book Image

Modernizing Drupal 10 Theme Development

4 (1)
By: Luca Lusso

Overview of this book

Working with themes in Drupal can be challenging, given the number of layers and APIs involved. Modernizing Drupal 10 Theme Development helps you explore the new Drupal 10’s theme layer in depth. With a fully implemented Drupal website on the one hand and a set of Storybook components on the other, you’ll begin by learning to create a theme from scratch to match the desired final layout. Once you’ve set up a local environment, you’ll get familiarized with design systems and learn how to map them to the structures of a Drupal website. Next, you’ll bootstrap your new theme and optimize Drupal’s productivity using tools such as webpack, Tailwind CSS, and Browsersync. As you advance, you’ll delve into all the theme layers in a step-by-step way, starting from how Drupal builds an HTML page to where the template files are and how to add custom CSS and JavaScript. You’ll also discover how to leverage all the Drupal APIs to implement robust and maintainable themes without reinventing the wheel, but by following best practices and methodologies. Toward the end, you’ll find out how to build a fully decoupled website using json:api and Next.js. By the end of this book, you’ll be able to confidently build custom Drupal themes to deliver state-of-the-art websites and keep ahead of the competition in the modern frontend world.
Table of Contents (21 chapters)
1
Part 1 – Styling Drupal
12
Part 2 – Advanced Topics
17
Part 3 – Decoupled Architectures

Styling the search results page

Drupal core provides a simple module to perform searches, but it’s tailored to a very simple websites that doesn’t need any advanced features.

On the demo website, we’ll use the Search API contributed module (https://www.drupal.org/project/search_api). One of the main advantages of Search API is that for every search index, the module provides us with a data source that we can use in a view.

The demo website defines a view that queries the search index; you can find it at https://packt.ddev.site/search.

The search view renders indexed contents (nodes) using a specific display mode called Search index. Check the configuration of every content type to see that such a display mode is present in any of them.

Using a specific display mode for search results is not mandatory, but it’s useful to normalize every content type to render a uniform markup. Having a unique display mode for every content type allows us to define...