I Have a display mode that renders out two optional fields in the sidebar, via a Display mode called 'Content sidebar', this is done using a 'Entity view (Content:[node type])' 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

Status: Active » Closed (duplicate)
realityloop’s picture

Title: Entity view (Content:[node type]) block causes region to be rendered when nothing visible in block » Entity view (Content:[Display mode]) block causes region to be rendered when nothing visible in block
vaccinemedia’s picture

@realityloop you say this is a duplicate but have not referenced the duplicate issue

jumoke’s picture

I am having this issue as well, where is the duplicate?

weseze’s picture

Status: Closed (duplicate) » Active

I'm also unable to find the actual duplicate issue, so setting back to active.

ecvandenberg’s picture

This is already an old issue. I find this rendering of empty entities very annoying behavior. Are we alone out there? Are we missing something?

Does anyone know more about how to deal with this?

yakoveka’s picture

Here is the duplicate, but it's not fixed yet: https://www.drupal.org/project/drupal/issues/953034

avpaderno’s picture

#953034: [meta] Themes improperly check renderable arrays when determining visibility is about themes, while this issue is about entity views. I am not sure that fixing that issue would fix this issue too.