Skip to main content
Share Your Experience: Take the 2024 Developer Survey
3 of 5
Update
rickh
  • 33
  • 4

How to hide a block in a view when an exposed filter is being applied?

I have built a view with exposed filters. There is a 'popular content' block on this page which I am controlling using the Context module (https://www.drupal.org/project/context)

I would like it so that the popular content displays, but only if no filters are being applied to the view. If a filter is applied then the block should not show.

I can see that the Context module has a query string condition option which I've tried to apply but without success. I've tried adding things like ~?title=* or ~*?title=** here but I can't seem to get the behaviour I'm after.

Any help would be appreciated.

UPDATE I've used the answer from @Pierr.Vriens to create a rule component. However, the block now isn't showing on the /MyViewPath page (which is /courses on my site). I've attached a screenshot on how I've set it up. I'm surprised that it's not showing on the page now at all. The block is being set in the correct region, the 'rules' component has been added to the block settings itself and I've disabled the context module from messing with it too.

Here is an export of the rule I created:

{ "rules_block_visibility_popular_courses" : { "LABEL" : "Hide block for filtered course view", "PLUGIN" : "rule", "OWNER" : "rules", "REQUIRES" : [ "rules" ], "USES VARIABLES" : { "module" : { "label" : "Module", "type" : "text" }, "delta" : { "label" : "Delta", "type" : "text" }, "result" : { "label" : "Result", "type" : "boolean", "parameter" : false } }, "IF" : [ { "text_matches" : { "text" : [ "site:current-page:url" ], "match" : "courses " } } ], "DO" : [ { "data_set" : { "data" : [ "result" ], "value" : "1" } } ], "PROVIDES VARIABLES" : [ "result" ] } }

rickh
  • 33
  • 4