Drupal 8 Tutorials – Blocks


Blocks, Blocks, and More Blocks

A block is a generic term that is applied to any self-contained piece of content, menu, or code. There are standard prebuilt blocks that come with Drupal 8: the “User login” block, the Search block, the “Who’s online” block, the “Who’s new” block, the “Recent content” block, and more. There are also blocks that come with contributed modules, such as blocks that share the latest weather report, your recent Twitter posts, or your current Facebook status. As a site administrator you can construct your own custom blocks, such as a list of upcoming events.

Making Blocks Appear on Pages

I’ll now show you how to assign anywhere from one to dozens of blocks to the various regions on your theme, and explain how doing so increases visitor interest in your site by providing interesting and high-value features. Most Drupal developers know the technique, but we’ll quickly go through it.

Finding the List of Available Blocks

To find the list of blocks that are available for you to use on your new website, click the Manage link at the top of the page, then click the Structure link in the secondary menu. This takes you to the Structure page. On the Structure page, click the “Block layout” link to reveal the “Block layout” page, which lists all the defined blocks on your system, including those that are already assigned to regions and those that are not assigned to a region.

On the “Block layout” page you will see that Drupal 8 provides a number of prebuilt blocks that can be placed on pages on your site. Pick a few by selecting from the list of blocks in the “Place blocks” box in the right column of the page. Click the title of a block and, on the “Configure block” form, pick a region from the select list (e.g., Sidebar First if you are using the Bartik theme). After assigning the blocks to regions, click the “Save blocks” button. If you return to your site’s homepage, you’ll now see the blocks that you enabled in the regions where you assigned them.

Rearranging Blocks

It is likely that, at some point in time, you’re going to want to reorder how blocks appear on a page. To reorder the blocks, navigate to the “Block layout” page as described in the previous section. On the “Block layout” page, simply click and hold the plus sign (+) next to the block that you want to move, and drag that block to the position where you want it in the list of blocks for that region. When you release the mouse button, you’ll see that Drupal reordered the items (temporarily). You’ll see a message at the top of the list of blocks stating “You have unsaved changes.” Scroll to the bottom of the page and click “Save blocks.” Drupal will save the changes and display a message stating that the changes were made. Return to the homepage by clicking the “Back to site” link at the top left of the page and you will see the blocks in their new order.