1

I have a content type and what I want to do is show a block on the right hand side only if the user is viewing that content type using a custom module. Any general pointers as to where I should start looking?

  • You are talking about only one content type? – CodeNext Aug 15 '16 at 21:46
  • Yes. It needs to be done programmatically and not using the ui. Sorry – kratos Aug 15 '16 at 22:01
1

This can be done in a few ways.

If your content type always has a unique URL (such as /news) you can set the block to only show when on a page matching that URL.

Or this can be managed in a variety of ways using different plugins that allow for the manipulation of displaying content types and their corresponding views/blocks.

Are you currently using any plugins like that or have any themes installed?

  • No this is just assuming that I am using bartik theme. The url is the standard node/1 or node/2 etc etc. Any way we know programmatically if user is on certain content type? – kratos Aug 15 '16 at 21:45
  • @kratos once again, in a few ways. Each page has an automatically generated name when it is made that includes the content type, so you could reference the block by body.page-contentType .block and either display/hide it using JavaScript or CSS or really any way you prefer. You can see this name by inspecting the page using a browsers development tools. – Atom Aug 15 '16 at 21:48
  • @kratos did this work? – Atom Sep 13 '16 at 13:46

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.