Check if block is enabled for current page?

Created on 18 December 2016, over 7 years ago
Updated 26 March 2024, 3 months ago

I'm currently printing a block in my region.html.twig using for example
{{ drupal_block('bartik_powered') }}

Can I somehow only show the block on pages for which it is enabled in the Block Layout page?

I tried

{% if drupal_block('bartik_powered') %}
  {{ drupal_block('bartik_powered') }}
{% endif %}

But that if-condition seems to return TRUE for every page, not just for the 5-6 pages the block is enabled on.

πŸ’¬ Support request
Status

Fixed

Version

1.0

Component

Miscellaneous

Created by

πŸ‡§πŸ‡ͺBelgium Puppetmast0r

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Seems only enabled blocks have a weight, so I did it like this:

    {% if drupal_entity('block', 'volcano_search_autocomplete')['#weight'] is defined %}
      ...
    {% endif %}
    
Production build 0.69.0 2024