1

I've found plenty of posts about changing the visibility of a block programatically.

My problem is the opposite. Given a block's ID/delta, how do I find out if it should be displayed at the current path?

I have a field collection that allows you to append a block using the Block Reference module (I preprocess the field collection and use my own template, so the logic has been taken away from the Block Reference module). It works, but I only want it to kick in if the "Show block on specific pages" rule says that block should be displayed.

0

To test the block style visibility rules, you can use drupal_match_path

For example, in core: block_block_list_alter

Checks the page, user role, and user-specific visibility settings. Removes the block if the visibility conditions are not met.

  • Thank you. This is the approach I ended up using. I was hoping that Drupal would offer that as part of the block loading process as it feels somewhat like reinventing the wheel, but so be it. – Geat Feb 2 '17 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.