Load a custom block and render with subset of data I am loading a block programmatically in a theme preprocess function, and trying to render that block in twig using without to remove some fields. However, the block is still printed in full.

This is the code I am using.

function my_preprocess_node(&amp;$variables) {
    $footer_narrow = \Drupal\block\Entity\Block::load('my_block');
    $variables['my_block'] = \Drupal::entityManager()
      -&gt;getViewBuilder('block')
      -&gt;view($my_block);
}


The template code is the following one.

{{ my_block|without('field_1', 'field_2') }}


I also noticed while debugging, that while the result in twig of my_block is a render array, it does not include the keys I'm expecting (the problem, I assume?).

This is the dump() output.

array(3) {
  '#cache' =&gt;
  array(4) {
    'keys' =&gt;
    array(3) {
      [0] =&gt;
      string(11) "entity_view"
      [1] =&gt;
      string(5) "block"
      [2] =&gt;
      string(17) "my_site_footer"
    }
    'contexts' =&gt;
    array(3) {
      [0] =&gt;
      string(28) "languages:language_interface"
      [1] =&gt;
      string(17) "my_theme_section"
      [2] =&gt;
      string(14) "my_theme_site"
    }
    'tags' =&gt;
    array(2) {
      [0] =&gt;
      string(10) "block_view"
      [1] =&gt;
      string(36) "config:block.block.my_block"
    }
    'max-age' =&gt;
    int(-1)
  }
  '#weight' =&gt;
  int(0)
  '#lazy_builder' =&gt;
  array(2) {
    [0] =&gt;
    string(42) "Drupal\block\BlockViewBuilder::lazyBuilder"
    [1] =&gt;
    array(3) {
      [0] =&gt;
      string(17) "my_site_footer"
      [1] =&gt;
      string(4) "full"
      [2] =&gt;
      NULL
    }
  }
}
One way to do this is with a new view mode for blocks. You can add one at /admin/structure/display-modes/view/add (Manage > Structure > Display Modes > View Modes > Add new view mode). Then, you have two options, 1. go to your custom block type and configure this view mode display to only have the fields you want, or 2. create a template file with a name like block--BLOCK-TYPE--MY-NEW-VIEW-MODE.html.twig, then remove the fields you don't want to print like you were trying to do in the node template. (Replace BLOCK-TYPE with your block type's machine name, and MY-NEW-VIEW-MODE with the machine name of the new view mode you created. Convert all underscores in these machine names to dashes.) After you've done this you can update your preprocess hook's view() call like -&gt;view($my_block, 'MY_NEW_VIEW_MODE')(keep the underscores in the machine name of your view mode here). This will make your preprocess hook look like:

function my_preprocess_node(&amp;$variables) {
  $footer_narrow = \Drupal\block\Entity\Block::load('my_block');
  $variables['my_block'] = \Drupal::entityManager()
    -&gt;getViewBuilder('block')
    -&gt;view($my_block, 'MY_NEW_VIEW_MODE);
}


Lastly, because you add your block to the variables array with the my_block key, update your node's twig template to simply be:

{{ my_block }}