Include / Exclude styles

Last updated on
24 March 2021

The annotations "include" and "exclude" are available to restrict your styles from appearing on specific blocks. This is done by passing in a list block's plugin IDs.

Include: Only show style options on the defined blocks. This is like a Whitelist of blocks.

Exclude: Do not display style options for any of the defined blocks. This is like a Blacklist of blocks.

Choose one or the other. Don't use both "include" and "exclude" at the same time.

How to use

Pass in a "block plugin id" for a normal block or a "block content type" bundle name for a custom block type into the "include" or "exclude" attributes.

All derivatives of a normal block may be used by adding :* such as system_menu_block:*

Examples

Include only specific block content types

sample_block_style:
  label: 'Sample Block Style'
  include:
    - 'block_content_type'

Exclude specific blocks

sample_block_style2:
  label: 'Sample Block Style 2'
  exclude:
    - 'block_plugin_id'

Only show styles on the Basic custom block

sample_block_style3:
  label: 'Only for the Basic custom block'
  include:
    - 'basic'

Don't show styles on the Main Menu

sample_block_style4:
  label: 'Hide from the Main Menu'
  exclude:
    - 'system_menu_block:main'

Don't show styles on any menu

sample_block_style5:
  label: 'Hide from all Menus'
  exclude:
    - 'system_menu_block:*'

Discovering a Block's plugin ID

How to discover a 'block plugin id'

It might be frustrating at first trying to figure out how to get a block's plugin id. In a theme's themename.theme file just preprocess a block. One of the variables available is the plugin_id.

/**
 * Implements hook_preprocess_block().
 */
function themename_preprocess_block(array $variables) {
  // Get the plugin id
  $plugin_id = $variables['plugin_id'];
  print '<pre>' . $plugin_id . '</pre>';
}

How to discover the name of a "block content type"

All blocks created from block content types show the same base plugin id block_content. Thus, a the block's content type is it's machine name.

Go to /admin/structure/block/block-content/types and "Edit" one of the block types shown. To the right of the label will be a "Machine name". For example the "Basic block" type created by the Standard profile has a machine name basic

Help improve this page

Page status: No known problems

You can: