I have a website that uses themekey to display a different theme for one page. I use the context module to display blocks across the site (*). I tried to exclude the page I don't wish to display blocks on using ~, but it didn't work.

Essentially I followed this answer for my path setup: Exclude a block from specific parts of the website with the Context module

So in my path setting I have


That did not work as all the blocks listed in the context are still present. I even went so far as to create a second context with no blocks added for the path in question, but that didn't work either.

Edit: I also tried ~/my-page-to-exclude-all-blocks, but that didn't work either.

  • Not sure if this going to work but what if you switch * and ~ position?
    – Gulok
    Commented Jun 23, 2016 at 0:20
  • No that didn't work.
    – Webdrips
    Commented Jun 23, 2016 at 5:17

1 Answer 1


You could use the Rules block visibility module for this. Here is a quote from its project page:

The Rules block visibility module allows Rules components to be used to control block visibility. This provides Drupal administrators and developers extreme flexibility in controlling when blocks should be displayed on their websites, in addition to the default visibility options provided by Drupal.

The general idea is that if you can do it with Rules, you can use it to control block visibility, so the possibilities are limitless.

Need to show a block only for users registered more than a month ago?

Perhaps you have a block that must be shown only between 8am-5pm on weekdays?

What about displaying or hiding a block based on current weather conditions?

All of this can be done by using Rules block visibility.

With that, and as per the "if you can do it with Rules, you can use it to control block visibility" above, you've reduced your question to making Rules "check the path of the current page" (so that the block is not shown on that page on which you want to hide that block).

For an illustration of how to use this module, refer to my answer to "How to stop a Views block from displaying to admins, such as user/1?". It includes a Rules Component (in Rules export format), which you should replace by this variation of it to make it match your specific question):

{ "rules_block_visibility_exclude_a_page" : {
    "LABEL" : "Hide block for a specific page",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
      "module" : { "label" : "Module", "type" : "text" },
      "delta" : { "label" : "Delta", "type" : "text" },
      "result" : { "label" : "Result", "type" : "boolean", "parameter" : false }
    "IF" : [
      { "NOT text_matches" : {
          "text" : [ "site:current-page:url" ],
          "match" : "my-page-to-exclude-all-blocks"
    "DO" : [ { "data_set" : { "data" : [ "result" ], "value" : "1" } } ],
    "PROVIDES VARIABLES" : [ "result" ]

Adapt the value of my-page-to-exclude-all-blocks to fit your needs. Obviously, you can reuse the same Rules Component for all blocks you want to hide on that specific page.

Should you want to further enhance the above Rules Component (to make it more generic), just replace the Rules condition in it with something using an appropriate regular expression (related to the current path also).

Note: yes this requires (at least) 1 more module (Rules block visibility, and Rules which it depends on). I also always try to avoid modulitis (= way too much modules) in any Drupal site. However adding Rules to any site seems to me like a no-brainer, because you can avoid/eliminate dozens of other modules that do only 1 thing. And by using the (tiny) Rules block visibility module, you can potentially replace modules such as the Context module and/or reduce the need for custom modules and/or using the (dangerous) PHP filter.

  • Appreciate your answer, and that does indeed look like a very useful module that would solve my issue, but I'm trying to solve this without adding yet another module to an already overly complex site.
    – Webdrips
    Commented Jun 23, 2016 at 9:56
  • @Webdrips: merci for the feedback, check my "Note" I added ... Commented Jun 23, 2016 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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