Display a Field Image Outside of the Content Region in Drupal 7 Using Views

I had a project where they wanted a big header image to appear on some of the content pages, above the content. I knew this wouldn’t be too difficult to do, but I was a bit initially stumped as to how best to do it using Drupal 7. I didn’t want to have to install too many modules for it to work, so I decided to start with Views as that module would be installed on the site anyway (of course).

Turns out this is pretty easy to do using Views.

  • First I added an Image field to my Content Type. Then I set the display to Hidden for that field. Easy basic Drupal Content Types stuff so far. Nothing fancy.
  • Then I created a View. A block in this case, and had it display the image field I had created.
  • Under Advanced, I clicked on Contextual Filters. From the list, I chose Content (Nid). I want to filter out by the node id of the current page being viewed. Simple still.
  • Next under the contextual filter options under the When the Filter Value is Not Available  I chose Provide a Default Value and Content ID from the URL from the drop down options.

This simply gets the Content ID from the URL of the current page you are on and then passes it to the filter.

Very easy to setup and works just fine for me!

Leave a Reply

Your email address will not be published. Required fields are marked *