My Drupal 7 module creates a block, and then in admin I can make it available for the Article content type only. I would also like it to be available to the result page for a Product Search. This page is not of a normal content type and comes to life in hook_menu().

The path for the results will be avantlink-search-results/search term and I would like it to show the block with the search form again. I would rather not use the PHP code option in the block visibility options so as to keep it simple for users of the module.

The code is viewable on AvantLinker.


I think you may want to take a look at the context module. That allows you to define multiple conditions for displaying blocks.

However, you should also consider making your module only return content on pages that it makes sense to appear on. So the user doesn't have to worry about complex configuration.

  • The context module is only beta for D7 and with a lot bugs getting light attention. That would be too much for people new to Drupal like the potential users of my module.
    – bumpaw
    May 17 '11 at 18:21

You could use the Rules block visibility module for this. ... which doesn't require the PHP filter to be enabled. 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 only shown on your "result page for a Product Search", as in your question).

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_popular_courses" : {
    "LABEL" : "Hide block for filtered course view",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
      "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" : "avantlink-search-results/",
          "operation" : "starts"
    "DO" : [ { "data_set" : { "data" : [ "result" ], "value" : "1" } } ],
    "PROVIDES VARIABLES" : [ "result" ]

If needed, further adapt the value of avantlink-search-results/ to fit your needs. And/or replace the Rules condition in it with something using an appropriate regular expression.


If you only want the block to show up on certain pages, the block admin settings page is already fit to do that. If you are using URL aliases (say the URL alias for the article content type is example.com/article/....) and not using the PHP filter, you could try: Block settings

Unless I missed something in the question, this should work in a basic setup.

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.