The Block field module lets you insert a Drupal block as a field on your content.
A Drupal theme is divided into regions and you can place blocks or your own custom blocks into these regions. You accomplish this task by dragging and ordering blocks in the “Block Layout” screen. That means you can append blocks before or after the main content of your content type. This “Block Layout” screen will soon be cluttered if you have multiple content types and/or multiple single nodes, each one with a different custom block.
However, there’s a way to insert a block (or many blocks) directly into your content as a field. Thus, you don’t have to place the block in the “Block Layout” screen, instead, you insert the block as a field on the node.
In this tutorial, we’re going to cover the usage of the Block field module. Let’s start!
Installing the Block Field module
The first thing you’ll need to do is install the Block field module.
Using Composer:
composer require drupal/block_field
This module has no dependencies, so just install it and you’re good to go.
Add Block Field to Content Type
Let’s start by adding a block field to the Article content type.
1. Go to Structure, “Content types”, click “Manage fields” on the Article now, then click on “Add field”.
2. Select “Block (plugin)” under the reference category and give it a proper label.
3. Leave the “Allowed number of values” set to 1 and click “Save field settings”.
On the edit screen, you can add a default value for this field. There’s also a list of all blocks, which you can select or deselect in order to make them available to this particular field (custom blocks will appear here too). Click “Save settings” once again.
Test Block Field
Click Content, “Add Content”, Article in order to create a test article. Choose a system block (for example the “Powered by Drupal” block) from the drop-down and click Save.
You’ll see the selected block inserted as a field in the content. This block won’t appear in the “Block Layout” screen.
You can also use this module to insert a view via a block inside the content. Edit the article and select the “Who’s online” block under the “Lists (Views)” category, click Save and you will see this block in your content.
Please note: you won’t be able to use Views contextual filters with the Block Field module.
Summary
The Block Field module lets you insert not only block views into a field but all types of blocks, even custom blocks. This allows the creation of complex content types and/or nodes and provides great flexibility when building a site.
i have applied everything but it is not showing anything
Sorry to hear that you couldn’t get it working.
You’ll have to debug this further:
– Look for PHP errors
– Search the issue queue to see if others have had the same problem
I really can’t offer more help because you haven’t provided much information.
Good luck.
Cheers,
Ivan