I Have a display mode that renders out two optional fields in the sidebar, via a Display mode called 'Sidebar second', this is done using a 'Entity view (Content: Sidebar second)' block.

This Block is set to only display on a single content type however when viewing that content type the region is rendered even when the display mode to get rendered in the sidebar region has zero content content.

Rendered aside:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'region' -->
<!-- FILE NAME SUGGESTIONS:
   * region--sidebar-second--entity--node--canonical.html.twig
   * region--sidebar-second.html.twig
   x region.html.twig
-->
<!-- BEGIN OUTPUT from 'profiles/council/themes/custom/custom_theme/templates/layout/region.html.twig' -->
<div class="region region-sidebar-second">
    
  <!-- THEME DEBUG -->
  <!-- THEME HOOK: 'block' -->
  <!-- FILE NAME SUGGESTIONS:
     * block--entityviewcontent-sidebar.html.twig
     * block--entity-view--node.html.twig
     * block--entity-view.html.twig
     * block--ctools.html.twig
     x block.html.twig
  -->
  <!-- BEGIN OUTPUT from 'core/themes/classy/templates/block/block.html.twig' -->
  <div id="block-entityviewcontent-sidebar" class="contextual-region block block-ctools block-entity-viewnode">
    <div data-contextual-id="block:block=entityviewcontent_sidebar:langcode=en" class="contextual" role="form"><button class="trigger visually-hidden focusable" type="button" aria-pressed="false">Open  configuration options</button>
      <!-- THEME DEBUG -->
      <!-- THEME HOOK: 'links__contextual' -->
      <!-- FILE NAME SUGGESTIONS:
         * links--contextual.html.twig
         x links.html.twig
      -->
      <!-- BEGIN OUTPUT from 'core/themes/classy/templates/navigation/links.html.twig' -->
      <ul class="contextual-links" hidden="">
        <li class="block-configure"><a href="/admin/structure/block/manage/entityviewcontent_sidebar?destination=node/53">Configure block</a></li>
      </ul>
      <!-- END OUTPUT from 'core/themes/classy/templates/navigation/links.html.twig' -->

    </div>

    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'ds_entity_view' -->
    <!-- BEGIN OUTPUT from 'modules/contrib/ds/templates/ds-entity-view.html.twig' -->
    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'ds_reset' -->
    <!-- FILE NAME SUGGESTIONS:
       * ds-reset--node--53.html.twig
       * ds-reset--node-news-sidebar-second.html.twig
       * ds-reset--node-news.html.twig
       x ds-reset--node-sidebar-second.html.twig
       * ds-reset--node.html.twig
       * ds-reset.html.twig
    -->
    <!-- BEGIN OUTPUT from 'profiles/council/themes/custom/custom_theme/templates/ds-reset--node-sidebar-second.html.twig' -->
    <div class="l-container">
    </div>
    <!-- END OUTPUT from 'profiles/council/themes/custom/custom_theme/templates/ds-reset--node-sidebar-second.html.twig' -->
    <!-- END OUTPUT from 'modules/contrib/ds/templates/ds-entity-view.html.twig' -->
  </div>
  <!-- END OUTPUT from 'core/themes/classy/templates/block/block.html.twig' -->
</div>
<!-- END OUTPUT from 'profiles/council/themes/custom/custom_theme/templates/layout/region.html.twig' -->

Is there a way to only render out something if content would be visibly displayed by the block?

Comments

realityloop created an issue. See original summary.

realityloop’s picture

Discussion with EclipseGc on IRC also indicates that although there is likely an issue here that needs to get fixed in ctools, there is also a long standing core issue that will need to be resolved to stop the region from getting rendered:
https://www.drupal.org/node/953034