Using theme hook, how do I get block contents into the $comm line? if ( isset($vars['content']['#block_content']) ) { // check for custom content
    if ($vars['content']['#block_content']-&gt;type[0]-&gt;getValue()['target_id'] == 'js_file_block') { // only run on js_file_block types
      $storage = \Drupal::entityTypeManager()-&gt;getStorage('block-content');
      $comm = current($storage-&gt;loadByProperties(['type' =&gt; 'block']));
      $route_match = \Drupal::routeMatch();
      $vars['inlinejs2'] = array();
      if ($comm !== false) {
        foreach ($comm-&gt;get('field_js_url') as $script_block) {
          $vars['inlinejs2'][] = $script_block-&gt;value;
        }
      }
    }
  }


I dont know what I am doing wrong, but it will not make the array.
If you try to access the entity in a template preprocess hook, there is a much simpler way:

function MYTHEME_preprocess_block(array &amp;$variables) {
  // check for custom content block
  if ($variables['base_plugin_id'] == 'block_content') {
    // the entity is alreary availale in the preprocess hook, no need for another query
    $blockContentEntity = $variables['elements']['content']['#block_content'];
    // my advice: pass the entire entity to the template, so you can access all the block fields
    // in Twig without further preprocessing, similar to node templates, e.g.
    // {{ block_content.field_whatever.0.value }}
    $vars['block_content'] = $blockContentEntity;
    // further processsing only for custom content blocks of type 'js_file_block'
    if ($blockContentEntity &amp;&amp; $blockContentEntity-&gt;bundle() == 'js_file_block') {
        //...whatever you need in here...
    }
  }
}