This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Join our live AMA on the Future of Page Builders with Brizy's CEO! Register Now →

How to Create a Custom Block in Drupal 8

Updated on February 26, 2018

4 Min Read
Custom-Blocks

Drupal is popular mainly because of its flexibility. Almost anything in the robust CMS can be modified or customized to fit the needs of a website developer.

One of the main aspects of Drupal is the way it lays out a site page through ‘blocks’. Although there are some pretty useful and out of the box blocks available in Drupal, there are times when you need to create a custom block and Drupal makes it pretty easy to create one. However, for newbies navigating through the menus might be complex.

In this tutorial, I’ll show you how to create a custom block in Drupal.

Login to the Admin Panel

The first thing that you need to do is log in to Drupal as an admin. Now navigate to admin -> structure -> block layout -> custom block library.

Drupal block layout page

Custom Block Type

Once here, click the ‘Block types’ tab. Then click the blue ‘Add custom block type’ button.

Drupal custom block library

Now, enter the Label and Description of your custom block type, and click Save.

Custom block details

Nothing as Easy as Deploying Drupal Apps on Cloud

With Cloudways, you can have your PHP apps up and running on managed cloud servers in just a few minutes.

Edit Fields

You can now edit or add fields to your custom block type as required. Not only that, you also have the option to Manage display etc. Customize your block as much as you need. Here, I’ll be adding a file field. This will allow a user to download a particular file.

Manage Fields

Type of input

Add Custom Block

Now go back to the ‘Custom block library’ tab under Block Layout and click ‘Add custom block’ to add you block to the library.

Custom Block library Drupal

Here, you’ll see the block we created in the previous steps.

Add Custom Block Drupal

Now enter the block description, body and the file you wish for the users to download. Click Save and your block should appear in the list under ‘Custom Block Library’.

Place Block

All that’s left for you to do now is to place the block on the site. You can place it wherever you wish. I’ll be placing it in the 1st sidebar just as an example. You can do this by navigating to admin -> structure -> block layout.

Click the ‘Place Block’ button beside the region you want to place your block in. Since I’ll be placing it in the left sidebar, I can find the region and click ‘Place block.’ Here a list of blocks that will appear. Find your custom block and click ‘Place block’.

Place Custom Block Drupal
You will be presented with an option to set the visibility of the block. This way it’ll be visible for certain content types only. After making the appropriate changes, click Save. Now, go back to your site and look for the region you placed your block in.

Custom block on Drupal website

Conclusion

That’s it! You’ve successfully created your own custom block and placed it in your site. This was a very basic example of the custom block functionality. You can make blocks for certain content types, place it in any region, and create any type of block. There are a lot of possibilities and the customization is seemingly endless. Hope you found this tutorial useful.

If you have any questions, please leave me a comment and I’ll get back to you.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Hamza Zia

Hamza is a Drupal Community Manager at Cloudways - A Managed Drupal Hosting Platform. He loves to write about Drupal and related topics. During his free time, he can be seen obsessing over Football, Cars, Android and Gaming.

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now