2

I have a block view that gets its contents based on a contextual filter. I only want to use this filter if it's a certain node type being displayed ie. the block would use the contextual filter on basic pages but on article and other pages I would like to set the contextual filter to a default value.

One way I thought I might do this is to change the views display based on the node type and then override the settings in the second display. Is this possible?

I created my second display for the view and I added both blocks to the same region. One of them I set to only display on basic pages. The other one I would like to set to only not display on basic pages. The block system only lets me select which content types to show the block on not which content types to exclude it from. I don't want to keep coming back to this page and having to check more boxes as I add new content types.

Is there any way to exclude a block from being shown on a certain content type?

2 Answers 2

1

It's possible with views:

#1 Configure field with images:

enter image description here

#2 Add contextual filter:

enter image description here enter image description here

#3 Save the contextual settings and then add "No result behavior':

enter image description here

#4 You just need to display a default image in case the other content type than basic page, so you can apply the Unfiltered text, and type the html source of the image:

enter image description here

That's it!

7
  • thanks this looks like it will work. I have set up two contextual filters on the master view. one filters the content type and the other the node id (this is needed so it will display the right content inside the view) I set the content type contextual filter like your screenshot and reordered it to the first position. The problem is it is printing out all the header images. Because it is a block view the help text in the dialog says "no contextual filter value will be available unless you select 'Provide default'." maybe that is why? Commented May 26, 2013 at 21:50
  • Yes, if you leave the default setting: "Display all results for the specified field" - then all values will be listed. If the display should depend on the node ID, you can select "Provide default value" and choose: content ID from url
    – Jack-PL
    Commented May 26, 2013 at 22:00
  • I tried it but it displays the no results view on every page? Commented May 26, 2013 at 22:14
  • hm.. so, the only problem is with the quantity of images? It should be displayed only one?
    – Jack-PL
    Commented May 26, 2013 at 22:15
  • yes it should display only one image. each page that shows the view has a field for an image. If you are viewing a basic page the view should show the image from the image field. All other pages should see the no results view Commented May 26, 2013 at 22:19
1

Is there anyway to exclude a block from being shown on a certain content type?

Yes, there is. Download and enable the Context module. Create a new context which assigns the view block you created to a region as a result of being on a Basic Page node.

Context is a pretty fantastic module for controlling where blocks go. Definitely check it out and explore what it can do.

0

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.