Hi, I'm wondering if there is a way to apply output of a View ONLY to a specific node type?

More specifically, I have created a view with a page display that I would like to apply only to nodes of content type Product.
At first I thought it would be a good idea to use Node ID as an argument and apply it to a path of "node/%" but then I realized that it would affect all content types b/c it uses "node" in the path.

Someone may suggest using Ubercart if I am doing anything with Products, but I avoided using Ubercart b/c it has too many functions that I don't need.

Any help would be much appreciated.

Comments

merlinofchaos’s picture

Status: Active » Fixed

Views can't do this without some help, since you need something that will do routing. Page Manager + Panels can do routing on the node and allow displaying different content by node type.

Anonymous’s picture

thanks for the tip! i will look in to it!

Anonymous’s picture

it works! thank you so much!

Anonymous’s picture

Status: Fixed » Closed (fixed)
rondog489’s picture

Hi I am trying to achieve this same thing. I cant seem to find a module called 'Page Manager'. I found panels but thats it. Am I missing something?

merlinofchaos’s picture

Page Manager is part of CTools: http://drupal.org/project/ctools

lsdoc77’s picture

You can do it only with views..there is a workaround for this..

1.First you create a view with a page display and set the path to /node/% so that this view is shown on every node page..

2.You create two arguments :
a. The first is the nid with basic validation so that it displays only the current node...
b. Another argument with node->type validator:node and you chose the type of content that you want to override..(the argument type is left to Node Id).

So until now if you check you will see that you have the view printed for the content type that you selected in step 2b and nothing shown on the pages of the other content types. That's why you have to :

3. edit the 'empty text' of the view ( on the left column) and with the php input filter enabled paste the following code :

<?php
 if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
}
$node=node_load(arg(1));
print node_view($node);
?>

So if the content type of the current node is not the desired instead of printing nothing it manuallly prints the node..

I know it's a little bit messy to do all this circle instead of using panels , but I believe that with views you can do almost anything.. ;-)

haysuess’s picture

I tried the instructions in #7 and it is not working. It makes complete sense and I am sure I followed your directions correctly. Is there something else?

haysuess’s picture

Looks like you said it backwards...

The Node:nid argument validator should be node->type with the type you want to override checked and set to display empty text
The Node: type argument validator should be basic

That works for me!

datarazor’s picture

There are actually a zillion ways to do this (as is typical with Drupal).

For example: You can use Context to enable a Views block that grabs the argument and turns off the content region when satisfied. (or use the view as a "block-like" attachment.

Or you can use the module EVA and associate it to the particular node.
https://drupal.org/project/Eva

Or you can edit the node.tpl.php to load a view and pass it your NID value.

Or you can use a custom path for the view, and the argument for the node can be in the URL

Hope this helps someone to see the other ways of the Drupal-force.