0

I've created a Block in Views. I only want this Block to display if a boolean field on the node is ticked. The View itself should only display content that relates to the node. How can I do this?


When displaying content in Views that relates to a node, you can normally use "Context Filters ID: Node". This would allow a View to take over a node. But it only seems to work in the Page display of the View and not the Block display.

I now I can use modules such as Rules, Panels or Node Fields Block to achieve this. But those are quite big modules and I only want to use it for a small thing on my site, so I was hoping their might be some solutions that can be done without any extra modules.

1

This should work in Views for blocks as well if you choose "Content: Nid" under "Contextual filters" and then add that boolean field as a "Filter criteria".

  1. Choose Content: Nid as contextual filter.

  2. Choose Provide default value

  3. Choose Content ID from URL as type of cont. filter.

  4. Choose that boolean field's value under Filter criteria.

When you're creating a view, under "Show" choose Content.

  • 1
    Yes this works. Extra tip: You must set the default value for "WHEN THE FILTER VALUE IS NOT AVAILABLE". You must also make sure that NO RESULTS BEHAVIOR is empty to hide the view for when the field is not ticked. – big_smile Apr 3 '15 at 11:05
1

The context module lets you conditionally display blocks on pages. context_entity_field then would let you set a condition based on the boolean field in your node.

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.