Using Custom Blocks

Why use a Custom Block?

Many site editors are learning how easy it is to edit their Drupal 9 websites with the variety of blocks available. When building and editing blocks on your website the first question to ask is yourself, is what will this block for used for?

The reason for the question is that if you think the same information needs to be presented in multiple places within your website, there is a time-saving trick that isn’t often well known or utilized. In this case, building a single block in the custom block library is better choice than creating multiple blocks with the same information on individual pages.

What is a Custom Block?

A custom block gives an editor the option to create one node of information and place it on multiple pages. Footer blocks at the bottom of a website are usually built this way so that they display on all the pages of a website. Other use cases may be to create a block with a Newsletter sign up form, to direct students on how to declare a major or creating a call to action link to contact an advisor.

Creating the Custom Block

  1. In the Manage administrative menu, navigate to Structure > Block Layout > Custom Block Library.
    /admin/structure/block/block-content
  2. Click Add Custom Block. The add custom block page appears
  3. Choose the block you would like to add. (For example, a Beyond Basics Block)
  4. Fill out the fields as you would for any Beyond Basics Block, adding a title, choosing the heading level, the body and any additional styles as desired.
  5. Save the block.

Placing the Custom Block

  1. Navigate to the page that you’d like to place the Custom Block
  2. Click Layout and navigate to the specific area you’d like the custom block to be placed. (If necessary, add a section, then click Add Block.) 
  3. When the Choose a Block interface appears, in the blank field, where it says (Filter by block name) type in title of the custom block you just created.
  4. You can choose to display the title, or not by unchecking the “display title” box.
  5. Add the block.

Last thoughts about Custom Blocks

  1. The custom block can be placed on multiple pages without recreating the block on every page.
  2. Edit your custom block within the custom block library, not on the page where the block is displayed.   /admin/structure/block/block-content
  3. When you edit the content using the Custom Block Library, the content will be updated in every instance where you placed the custom block.