How to check if block is empty in page.html.twig In my page.html.twig I have 

&lt;h2&gt;{{ 'Block title'|t }}&lt;/h2&gt;
&lt;div class=""&gt;
  {{ drupal_block('leftblock') }}
  {{ drupal_block('rightblock') }}
&lt;/div&gt;


I want to display Block title only if my custom leftblock and rightblock are filled. 

Thanks.



I tried 

If I do in my my_module.module

function my_module_preprocess_page(&amp;$variables) {
  $block = Block::load('leftblock');
  if ($block) {
    $variables['leftblock'] = \Drupal::entityTypeManager()
      -&gt;getViewBuilder('block')
      -&gt;view($block);
  }
  $block = Block::load('rightblock');
  if ($block) {
    $variables['rightblock'] = \Drupal::entityTypeManager()
      -&gt;getViewBuilder('block')
      -&gt;view($block);
  }
}


and in my page.html.twig

{% if leftblock or rightblock %}
  &lt;h2&gt;{{ 'Block title'|t }}&lt;/h2&gt;
{% endif %}
&lt;div class="my-class"&gt;
  {{ leftblock }}
  {{ rightblock }}
&lt;/div&gt;


This {{ rightblock }} display the real content of the block in twig( when is filled ), but 
It always display Block title because the block have always something 

if I do  {{  dump(rightblock) }} i got this when the block is empty or filled.

array(3) { ["#cache"]=> array(4) { ["keys"]=> array(3) { [0]=> string(11) "entity_view" [1]=> string(5) "block" [2]=> string(22) "rightblock" } ["contexts"]=> array(2) { [0]=> string(28) "languages:language_interface" [1]=> string(8) "url.site" } ["tags"]=> array(2) { [0]=> string(10) "block_view" [1]=> string(41) "config:block.block.rightblock" } ["max-age"]=> int(-1) } ["#weight"]=> int(0) ["#lazy_builder"]=> array(2) { [0]=> string(42) "Drupal\block\BlockViewBuilder::lazyBuilder" [1]=> array(3) { [0]=> string(22) "rightblock" [1]=> string(4) "full" [2]=> NULL } } }

I have two themes :

block-myLeft.html.twig

block-myRight.html.twig
You could preprocess your template 

function mytheme_preprocess_page(&amp;$variables) {
  $block = \Drupal\block\Entity\Block::load('leftblock');
  if ($block) {
    $variables['leftblock'] = \Drupal::entityTypeManager()
      -&gt;getViewBuilder('block')
      -&gt;view($block);
  }
  $block = \Drupal\block\Entity\Block::load('rightblock');
  if ($block) {
    $variables['rightblock'] = \Drupal::entityTypeManager()
      -&gt;getViewBuilder('block')
      -&gt;view($block);
  }
}


Than you can do this in your template

{% if rightblock or leftblock %}
  &lt;h2&gt;{{ 'Block title'|t }}&lt;/h2&gt;
{% endif %}
&lt;div class=""&gt;
  {{ leftblock }}
  {{ rightblock }}
&lt;/div&gt;