Using theme hook, how do I get block contents into the $comm line?
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...
    }
  }
}