Language
  • English
  • Français
Drupal custom theming or module development price estimate calculator

Theming Node type

I have a gallery created with Views, however when I click on the thumbnail, the default node type (content type) is displayed. I thought that it would be possible to create a View for the Content (node) type, but I do not see how do this? So to theme the node type do I have to do that in the template file or create a node_type.tpl file?
I would have thought it would be possible to associate a view to a content type (node type), so every time the node type is displayed it automatically picks up the view? i.e. Create node type video, create a view for video, and every time a video is selected it uses the video view. Thanks for helping with the learning.

node tpls

Aaron's picture

To theme the layout for a particular content type you need to create a file called node-yournodetype.tpl.php. So to theme the blog node type it would be node-blog.tpl.php. The only mistake I see that you made was using an underscore instead of a hyphen.

Getting the view to only show a particular node type just requires adding a filter and using the node type option. Once you create a view for a particular content type having that view show up when a particular content type is loaded (such as the video example) would require loading the view from within the node-video.tpl.php content type by the means of php. To understand how to insert the view into the tpl see this tutorial http://www.pixelclever.com/how-programmatically-insert-a-view-drupal-6 .

Thanks Aaron, that has made

Thanks Aaron, that has made things much clearer and the tutorial very helpful. I am not sure why I did not pick up that was the way it has to be done. So I am presuming if you insert a view then the theming is done on the view?

I followed the instructions

I followed the instructions and used your php snippet to relate the view to the video node type, however, in my case the same video shows each time (the first in the gallery), however the title and the comments relate to the video thumbnail clicked? What am I missing here? Thanks

Ok worked it out. Added the

Ok worked it out.
Added the argument Node: Nid to specify a single node and then send the argument so the code that inserts the view looks like this.
<?php
$view_args = array( $node->nid );
$display_id = 'Page_1';
$view = views_get_view('viewname');
if (!empty($view)) {
print $view->execute_display($display_id , $view_args);
}
?>

array( $node->nid ); - ???

array( $node->nid ); - ???

All this means is that the

Aaron's picture

All this means is that the view arguments is an array with only one item, and that item is set by the nid of the current node.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Ask a question related to Drupal development or administration