I am trying to create a new twig template that defines different types of views templates - or some sort of option based format.

Example 1:

Generic view blocks: block--views-block.html.twig

Example 2:

News Block specific views with no container: block--views-block--news-elements-block-1.html.twig

Example 3:

List Block specific views with no container: block--views-block--list-elements-block-1.html.twig

What i want to achieve: - if i can present an option on the block, that would also work.

Views block with no container: block--views--no-container--block.html.twig

So far:

function THEME_theme_suggestions_alter(array &$suggestions, array $variables) {

  // dpm($variables);

  // $content = $variables['elements']['content'];
  // if (isset($content['#block_content']) && $content['#block_content'] instanceof \Drupal\block_content\BlockContentInterface) {
  //   $suggestions[] = 'block__' . $content['#block_content']->bundle();
  // }

1 Answer 1


For my circumstance i have adopted to use the block_alter hook to define the new suggestion for the template. Since homepage only contains the unique views template and the others wouldn't.

function THEME_theme_suggestions_block_alter(&$suggestions, $variables) {
  $path_check = \Drupal::service('path.matcher');

  if (in_array("block__views", $suggestions) && $path_check->isFrontPage() == FALSE ) {
    $suggestions[] = 'block__views__blah__custom';


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.