4

I have created the custom page and assigned for the Underwriting content type nodes like underwriting/, but I want to restrict the block for a node of that content type; for example, show it for underwriting/, but not for underwriting/example.

Is it possible to restrict a block for particular sub-path, and allow it for all the other sub-paths of a specific path?

2

Assuming all of your underwriting/* nodes are of a certain content type and this content type does not have anything else than underwriting/* as path

Go to /admin/structure/block and find your block and click on Configure link.

Then under Visibility settings, Pages tab, select all pages except for underwriting/example

enter image description here

and then

enter image description here

| improve this answer | |
  • I have given as A/* here . But I dont want to show this block for A/a. I want to give A/* and also restrict for A/a. – logeshvaran Feb 4 '17 at 10:39
  • @logeshvaran Updated answer. Sorry I miss understood your question, you could do this with a combination. Assuming all of your A/* nodes are of a certain content type and this content type does not have anything else than A/* as path. – No Sssweat Feb 4 '17 at 10:57
  • 1
    Sorry, but IMO with this configuration the block would show on ANY page (of that content type) with a path that is NOT "underwriting/example" ... True, this solution works for pages such as "underwriting/some/other/example" (that part is correct) but the block would also be shown for pages with a path like "what/is/pierre/talking/about" (which is a path that does NOT start with "underwriting" ... (and that's the part that IMO is wrong ...). Too bad, but using Rules (as in my answer) is the only solution (unless you agree with the alternative that requires enable of PHP filter). – Pierre.Vriens Feb 4 '17 at 11:37
  • 2
    OK, with these (bold) assumptions (limitations?) your answer might work also. – Pierre.Vriens Feb 4 '17 at 11:57
  • 1
    @No SSSweat Thanks for your great idea. Its working – logeshvaran Feb 6 '17 at 10:30
0

Have a look at the Rules block visibility module. 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.

As per the "if you can do it with Rules, you can use it to control block visibility" above, you have the power of Rules available to implement all sorts of custom logic.

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_show_on_selected_pages" : {
    "LABEL" : "Show block on selected pages",
    "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" : [
      { "AND" : [
          { "text_matches" : {
              "text" : [ "site:current-page:path" ],
              "match" : "underwriting\/",
              "operation" : "starts"
            }
          },
          { "NOT text_matches" : {
              "text" : [ "site:current-page:path" ],
              "match" : "\/example",
              "operation" : "ends"
            }
          }
        ]
      }
    ],
    "DO" : [ { "data_set" : { "data" : [ "result" ], "value" : "1" } } ],
    "PROVIDES VARIABLES" : [ "result" ]
  }
}

Voilà ... Easy, no?

PS: no need for the (dangerous) PHP filter either (which is no longer in D8 core either ...).

| improve this answer | |
0

You need to enable the PHP filter core module. You will get a new option for a block restriction.

enter image description here

More Info

Restricting blocks to certain pages

<?php
if (arg(0) == 'underwriting' && arg(1) != 'example') {
  return TRUE;
}
else {
  return FALSE;
}
?>
| improve this answer | |

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.