Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Modernizing Drupal 10 Theme Development

You're reading from  Modernizing Drupal 10 Theme Development

Product type Book
Published in Aug 2023
Publisher Packt
ISBN-13 9781803238098
Pages 360 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Luca Lusso Luca Lusso
Profile icon Luca Lusso

Table of Contents (21) Chapters

Preface 1. Part 1 – Styling Drupal
2. Chapter 1: Setting up a Local Environment 3. Chapter 2: Setting a New Theme and Build Process 4. Chapter 3: How Drupal Renders an HTML Page 5. Chapter 4: Mapping the Design to Drupal Components 6. Chapter 5: Styling the Header and the Footer 7. Chapter 6: Styling the Content 8. Chapter 7: Styling Forms 9. Chapter 8: Styling Views 10. Chapter 9: Styling Blocks 11. Chapter 10: Styling the Maintenance, Taxonomy, Search Results, and 403/404 Pages 12. Part 2 – Advanced Topics
13. Chapter 11: Single Directory Components 14. Chapter 12: Creating Custom Twig Functions and Filters 15. Chapter 13: Making a Theme Configurable 16. Chapter 14: Improving Performance and Accessibility 17. Part 3 – Decoupled Architectures
18. Chapter 15: Building a Decoupled Frontend 19. Index 20. Other Books You May Enjoy

Building a Decoupled Frontend

We can use a decoupled approach when planning how to implement the frontend for a Drupal website.

In this chapter, we’ll explore some solutions available for building a JavaScript application that queries a Drupal backend to retrieve the information to render.

The first section discusses how Drupal exposes its content to the external systems. In the second part, we’ll build a frontend using a handmade solution with vanilla JavaScript and then with Next.js.

The topics covered in this chapter will be as follows:

  • Setting up the environment to build a decoupled site
  • Introduction to Next.js

Technical requirements

To run the examples in this chapter, make sure to follow the instructions explained in Chapter 1, Setting Up a Local Environment.

You can find the code for this chapter in the GitHub repository: https://github.com/PacktPublishing/Modernizing-Drupal-10-Theme-Development.

Setting up the environment to build a decoupled site

Since Drupal 8, the CMS can natively expose its internal structures (entities and configurations) to third-party systems.

With minimal or no configuration, you can start building the frontend of a Drupal website without using Twig and instead choose one of the many available JavaScript frameworks (such as Next.js, Vue.js, or React).

Drupal core provides two modules that can be used to expose content and other data to the to external systems:

  • RESTful Web Services
  • JSON:API

Both modules have pros and cons, and you should choose the one most appropriate for your use case. Sometimes, to fulfill requirements for some complex websites, you may have to use both.

In the following sections, we’ll expose data first with RESTful Web Services and then with JSON:API module to feed some vanilla JavaScript code. The output will be a fully decoupled HTML page that renders the details of a trip.

Figure 15.1 – A trip node rendered in a plain HTML file ...

Introduction to Next.js

There are multiple ways to implement a decoupled frontend for Drupal using one of the many available frontend frameworks.

It’s mostly a matter of taste. You can use Angular, Vue.js, or React; all of them have some support for Drupal and its API.

Here we’ll use one of the community’s latest solutions: Next.js for Drupal (https://next-drupal.org).

Next.js

Next.js (https://nextjs.org) is a powerful and popular open source framework for building modern web applications and websites. Developed on top of React.js, Next.js simplifies and streamlines the process of creating dynamic and server-rendered applications. One of its key features is its ability to handle both client- and server-side rendering, allowing developers to balance performance and user experience. Next.js also provides built-in support for automatic code splitting, enabling efficient loading of only the necessary components for each page. With an intuitive API and a...

Summary

The Next for Drupal integration we covered in this chapter leveraged Next.js’s capabilities for server-side rendering, static site generation, and an enhanced user experience, while Drupal continued to serve as the backend CMS for managing and storing content, users, and other site data. By combining these technologies, developers can create high-performance, scalable, and SEO-friendly websites, taking advantage of the best features of both Next.js and Drupal in a cohesive manner.

We have completed a long journey to prepare our Drupal site for production. Along the way, you have gained extensive knowledge of how Drupal transforms data into HTML pages and API endpoints. However, technology advances rapidly, and the community releases a new version of Drupal every six months. As the focus is on user and developer ease of use, keeping up with news on upcoming Drupal versions is essential.

So, keep learning!

lock icon The rest of the chapter is locked
You have been reading a chapter from
Modernizing Drupal 10 Theme Development
Published in: Aug 2023 Publisher: Packt ISBN-13: 9781803238098
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}