How to use custom blocks and paragraph types in Drupal


Quick summary

This guide will closely examine two important features in Drupal custom blocks and Drupal paragraph types. We’ll show you, step by step, how to use these tools to make your website more exciting and easy to use. Whether you’re building a website for the first time or looking to add more cool features to your site, this guide has helpful tips and instructions to get you going.


This guide will closely examine two important features in Drupal custom blocks and Drupal paragraph types. We’ll show you, step by step, how to use these tools to make your website more exciting and easy to use. Whether you’re building a website for the first time or looking to add more cool features to your site, this guide has helpful tips and instructions to get you going.

What are custom block types in Drupal?

With the launch of Drupal 8 and its continued development in Drupal 9 and Drupal 10, block types have brought about a significant paradigm shift in site customization. This feature allows developers to create custom block types in Drupal, each with its unique set of fields and settings, facilitating a granular level of customization that was previously challenging to achieve. These adaptable blocks can be placed across a website in various positions, significantly enriching the user experience with content ranging from static informational snippets to dynamic, interactive features.

Adding block types has essentially redefined what’s possible with Drupal, offering a robust toolset for developers to enhance site functionality and user engagement. By customizing these blocks to meet the specific needs of a project, developers can create unique, engaging, and interactive experiences for site visitors. Whether a custom block template in Drupal, a personalized user profile section, or an interactive product showcase, the ability to tune each block’s fields and settings finely empowers developers to push the boundaries of conventional web design and functionality.

This level of customization enhances a website’s aesthetic appeal, functionality, and user engagement. The strategic placement of these custom blocks, facilitated by thoughtful Drupal block layout considerations, can significantly improve site navigation and overall aesthetics, contributing to a more intuitive and visually appealing user experience.

What are paragraph types in Drupal?

Paragraph types in Drupal are not just tools; it’s a revolution in content management. This powerful module transforms the way content creators approach page layout design, allowing for the creation of complex, dynamic layouts that respond to the evolving needs of web audiences. With paragraphs, Drupal moves away from the rigid structure of traditional content management systems, offering a fluid, flexible approach that empowers content editors to construct pages using a variety of content elements. Each of these elements, or paragraph types, can be tailored with specific fields and settings, enabling a level of customization previously unattainable, highlighted by the Drupal paragraph type field templates.

Imagine having the ability to create a page where each section or paragraph can have a different layout, functionality, and content type. Text blocks can be mixed with image galleries, videos can be placed next to personalized quote blocks, and interactive slideshows can seamlessly integrate with user testimonials. The Paragraphs module simplifies the management of these diverse elements through an intuitive interface, making the content creation process more creative and significantly more efficient. This efficiency is crucial in enhancing Drupal paragraph type fields, allowing for the rapid deployment of high-quality content that meets the specific needs of users.

The implications of such flexibility are vast. Content creators can now design pages that are truly engaging, breaking free from the monotonous layouts that plague many websites. The ability to tailor each paragraph type with its fields and settings means the content can be incredibly diverse yet cohesive, providing a rich user experience that keeps audiences engaged and interested.

Steps to create custom blocks in Drupal

In the following sections, we’ll walk through the steps to create block types and paragraph types in Drupal. This section will explain the step-by-step processes involved, highlighting the versatility and power of Drupal’s content management capabilities.

1. Create a custom block type:

A. Navigate to the administrative path: `admin -> structure -> block layout -> custom block library.`

B. Activate the ‘block types’ tab, followed by the selection of ‘Add custom block type.’

C. Promptly input a discernible label and comprehensive description for your block type.

D. Integrate fields and undertake customization efforts, concluding with a click on ‘save.’

This foundational step facilitates the creation of a custom block type and underscores the importance of meticulous Drupal block type customization.

2. Add a custom block:

A. Revisit the custom block library.

B. Select ‘Add custom block.’ 

C. Appropriately position the block within your site’s layout through `structure/block-layout.`

The deployment process exemplifies the strategic application of Drupal block layout placement, enhancing site navigation and aesthetic appeal.

3. Programmatic implementation in custom themes:

A. Following block placement, a unique machine name is generated. Utilize this identifier to forge a path forward. 

B. Create a custom block template file within your theme’s template directory. For example, `block–machinename.html.twig` located at `/themes/Custom/Your theme/templates/block–machinename.html.twig`.

Now let’s see the steps to create paragraph types in Drupal:

1. Create a paragraph type:

A. Proceed to `admin/structure/paragraphs_type.`

B. Add a label and description for the paragraph type.

C. Add fields through `/admin/structure/paragraphs_type/your_type/fields.`

2. Use paragraph type with custom block type: 

Add the paragraph type as a field within your custom block type, fostering a harmonious blend of structure and content.

3. Accessing paragraph type data in custom block type: 

A. Create a paragraph template file, exemplified by `paragraph–paragraphtype-machinename.html.twig`.

B. Create a field template file, such as `field–paragraph–paragraphtype-machinename.html.twig`, situated at `/themes/Custom/Your_theme/templates/field–paragraph–paragraphtype-machinename.html.twig`.

4. Rendering paragraph type data in custom blocks:

  • Embed the following code within your block template file (`block–machinename.html.twig`) to access and display paragraph type data:

By adhering to these meticulously detailed steps, developers can adeptly create custom blocks and paragraph types in Drupal, unlocking the potential to craft rich, interactive web experiences. This exemplifies the platform’s flexibility and showcases the critical role of Drupal block layout considerations and programmatic customization in crafting unique digital narratives.

Introducing Khushbu Radadiya

This blog, authored by Khushbu Radadiya, a dedicated junior Drupal engineer at August Infotech, is a testament to her expertise and passion for Drupal website development. Radadiya’s work is characterized by a deep understanding of Drupal’s core functionalities, including custom block and paragraph types, which she skillfully applies to create rich, user-centric web experiences. Her contributions reflect her technical proficiency and commitment to advancing web development through innovative practices.

Spotlight on August Infotech  

August Infotech stands at the forefront of Drupal website development and custom CMS solutions, distinguished by its dedicated team of offshore developers. The company is renowned for its comprehensive approach to digital solutions, offering services from Drupal block type fields and settings customization to complete website development projects. August Infotech prides itself on its ability to deliver custom solutions that meet the unique needs of its clients, showcasing a commitment to excellence and innovation in the digital landscape.

Author : Khushbu Radadiya Date: February 28, 2024

Leave a reply

Your email address will not be published. Required fields are marked *