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.
Custom Block Type
Once here, click the ‘Block types’ tab. Then click the blue ‘Add custom block type’ button.
Now, enter the Label and Description of your custom block type, and click Save.
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.
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.
Here, you’ll see the block we created in the previous steps.
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’.
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.
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.