0

I have a block and I want to show it for specific content types and taxonomy terms. There is no common pattern for those pages.

For example, the URLs could be the following ones:

I don't want to show the block on the Demo content type, but on nodes of the content types, and term pages, without cloning/replicating the block.

How can I achieve this?

  • You'll need to use the conditions available when you edit the block. If conditions you need are missing, it's easy to create your own using the Condition API – Clive Jan 9 '18 at 12:09
  • 1
    Code won't help much when there is no common pattern. To build complex conditions try drupal.org/project/block_visibility_groups and the linked modules on the project page. – 4k4 Jan 9 '18 at 12:12
  • @4k4 Thank You, this module helped me and I got the results as desired. – FAB Jan 10 '18 at 6:40
0

If you control the code for the block, then it really is a simple matter of:

  • Defining the correct cache contexts (path probably)
  • In the build method, determining the context (getting current node, tax info from the node, and the like.)
  • Deciding what to output for the context
  • If you don't want to display it, return and empty build array (or NULL).

If you don't control the block content (e.g. view or 3rd party module), you can do the same as above and use the various methods to render the block from code.

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.