I want to create a template for a custom block type I've created by going to structure/block layout/ types/ add custom block type. The type I've created is called menu. How do i create a template for this custom block type from here? I'm not as familiar with Drupal so any help will be appreciated.
Asked
Active
Viewed 4,448 times
1 Answers
5
First, add theme suggestion to your theme, paste it into yourthemename.theme file
function yourthemename_theme_suggestions_block_alter(array &$suggestions, array $variables)
{
// Block suggestions for custom block bundles.
if (isset($variables['elements']['content']['#block_content'])) {
array_splice($suggestions, 1, 0, 'block__bundle__' . $variables['elements']['content']['#block_content']->bundle());
}
}
Now you can use theme suggestion per block bundle, copy block.html.twig to your theme and rename it to: block--bundle--your-block-type.html.twig

lamp5
- 392
- 3
- 11
-
As well as make sure you enable twig.debug in development.services.yml to ese a print of which twig template the page is using for that block. ( See https://www.drupal.org/node/2598914 ) – stacey.mosier Jun 20 '18 at 19:58