0

I need to pull a field from a content type and have it appear as a view in the sidebar next to the node it belongs to. I can't figure out what parameter to use in Views to indicate that my view block should appear by the node it was extracted from. Maybe something to do with relationships?

1 Answer 1

4

This can be done with contextual filters.

  1. Set up the view to display whatever information you need; put the view in a block that only displays on the page for that content type
  2. Add a contextual filter, selecting a field that contains the NID. For example, this could be content: nid
  3. For "when filter is not available" select "provide default value", then "content ID from URL"

After doing this, the view will only display the single result, where the NID field matches the NID of the node currently being viewed.

2
  • Thank you, it does seem to work, however it displays the view even when it is empty. Is there a way to work around that?
    – Jane
    Oct 8, 2013 at 11:08
  • This is a side effect of the contextual filter. There are a variety of ways to work around this; the best is to set the block itself to display only on the desired content page. Another solution is to add another contextual filter for "This Block (Override)" using global: null, hide view when filter is not available. Alternatively, you can set 'no results behavior' in the view 'advanced' settings to display a placeholder when there are no results.
    – ouni
    Oct 8, 2013 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.