Drupal 6: Template Suggestions for nodes in your View

Posted Nov 19, 2008 // 16 comments
George:

When themeing your view in Drupal 6, you have the ability to override the default templates. Depending on the "Style" and the "Row Style" attributes that you assign your view, different options are available to you. If you choose a "Node" row style, you can take advantage of a special template suggestion. You can create a .tpl file in your theme directory with the following naming scheme: node-view-VIEWNAME.tpl.php This template will be used to render each node in the view. It works almost the same as node-NODE TYPE.tpl.php but only for the view that you have specified.

About George

George Dickinson is a seasoned software engineer specializing in web development. He has been gaining experience the last 10 years by leveraging his computer science background and applying it in combination with leading web technologies to ...

more >

Read George's Blog

Comments

by akahn (not verified) on Wed, 11/19/2008 - 14:40

Does a node-based View with

Does a node-based View with a customized template have better performance than a field-based View with several fields from the node?

P.S. Your captcha is nearly impossible.

by nonsie (not verified) on Wed, 11/19/2008 - 15:55

fields vs node

actually it does not since it loads the entire node object.
Also re template names – in addition to node-view-VIEWNAME.tpl.php you can also use node-view-VIEWNAME-DISPLAYNAME.tpl.php

by ema (not verified) on Thu, 01/08/2009 - 09:46

But views is not using the

But views is not using the node_lod(nid) cached way?

by Drupal Theme Garden (not verified) on Thu, 11/20/2008 - 06:24

I tried your suggestion,

I tried your suggestion, but it doesn’t work (or I’m doing something wrong)

Instead, I have successful used views-view-fields—VIEWNAME.tpl.php instead of node-view-VIEWNAME.tpl.php

by Anonymous (not verified) on Mon, 04/27/2009 - 05:08

In the case of crashes, an

In the case of crashes, an export from MSInfo32, which you can launch by simply typing MSInfo32 into the Run box on your Start menu, so that we can see information about the operating system, running software and application errors.

by mpcoc (not verified) on Thu, 02/05/2009 - 10:30

Does a node-based View with a

Does a node-based View with a customized template have better performance than a field-based View with several fields from the node?

mpcoc

by Anonymous (not verified) on Mon, 12/28/2009 - 13:21

Did you find an answer for

Did you find an answer for this?D

by matt (not verified) on Thu, 02/05/2009 - 15:45

Thanks!

I think you just saved me lots of hair pulling, thanks you!

by ccshannon (not verified) on Fri, 02/06/2009 - 12:45

What am I doing wrong?

Hi, I'm hoping that someone can help me figure this out.

I'm building an Ubercart store, and I have a Vocabulary called "Brands". I created a Views view called "brands_view" to show all the products for each brand. I'm using D6.9 and Views2.2.

The view works using UI, but I need to add text to a field. Later, I would also like to merge two text fields into one string, so I can have "product_name By brand_name" as one on some views. For now, I'll settle for adding "By " to the front of the Term.

But I can't even seem to override one field template to add text.

I used "Theme Information" to get the filename I need to override the Term field.

I created views-view-field--brands-view--default--tid.tpl.php, placed it in my bluemarine folder (using it for both admin and production, for testing) and added some test text just so I could see it working.

I rescan Template files and Views sees it! I run a Preview, and it works! I'm home free, right?

Well, no. I go to my brands view page .... nothing! It doesn't get picked up!

I've emptied Views Cache and overall cache with devel.module and the Theme Registry has been reset, but my View doesn't show the changes!

I even created the suggestions hierarchy of files (views-view-field--brands-view--default--tid.tpl.php, views-view-grid--brands-view--default.tpl.php, views-view-fields--brands-view--default.tpl.php) thinking that woudl work but still .. nothing!

Has anyone else experienced this? It makes it kind of hard to theme my site when I can't alter my views appearance.

Note, I have 2 non-views templates: node-product.tpl.php and node.tpl.php. That works!

But Views templates? Not working. I'm wondering if there's a big bug in Drupal 6, but I have no idea.

I've spent the last few days scanning tutorials to see if I missed anything, but I think I'm doing everything right!

AAAAARRRRGGGGGGGHHHHHHHH! Okay, that helps to scream.

Anyway, any ideas are much appreciated. Thanks.

by ccshannon (not verified) on Sat, 02/07/2009 - 17:04

I know the answer, now. My curse is lifted.

Theme Information suggested this:

views-view-field--taxonomy-term--default--tid.tpl.php

and that didn't work, and it drove me nuts. This works:

views-view-field--taxonomy-term--tid.tpl.php

The display name "--default' should not be there. Phew!

And ....... exhale!

by DeveloperWun (not verified) on Sat, 04/25/2009 - 15:29

You should have added a display to your default view

I'm not sure, but I believe you get better performance if you add a display type to your view. If it's a block, then you add a block display. If it's a page, add a page display.

Make sure to save the view after adding a display type to it.

by moviemaniac (not verified) on Mon, 05/11/2009 - 09:09

About the template!

Hi guys concerning issues with template files, just do this simple thing: click on "theme" in the "basic settings" area. A series of templates will appear at the bottom of the page. You will a bold template name beside each plugin name. That is the template actually used for that plugin.

Each of the names reported in each row can be used as a template. Simply create a file with that name in your drupal theme's folder. Then reanalyze template files, then click ok, and then save your view. From now on you can modify your template in your theme folder and it will be used to display the nodes in your view. If you choose "node" as your row style (in basic settings) the views module will use the node default template, and this is a great thing I've just discovered. Hope this helps!

Thanks for this article!

by Terry (not verified) on Thu, 05/28/2009 - 15:35

I'm using the multiflex3

I'm using the multiflex3 theme on Drupal 5. I've created my frontpage using views, mini-panels and panelpage (its basically a panel page containing a few mini-panels and views). I did not use the theme's right-sidebar rather I sliced my panel-page to have a fixed-sized right column to display the adverts

But in the node page (when any node is clicked) the right column disappears, but I want a side bar to appear on the node pages as well and put an specific view there. If I enable the theme's right sidebar (to be displayed on the Node page) it ruins my front-page layout as well.

Any solution? I really appreciate your article and would be grateful if you could help me out.

Cheers

by Innovative Website Designs (not verified) on Mon, 07/13/2009 - 00:07

Nice tutorials. Really

Nice tutorials. Really helpful

by Club Penguin Cheats (not verified) on Sat, 08/29/2009 - 03:41

Well... I have one question:

Well... I have one question: Does a node-based View with a customized template have better performance than a field-based View with several fields from the node?

by Anonymous (not verified) on Wed, 10/14/2009 - 03:38

I can't get this working

For me, I've tried everything I can think of along withvyour suggestions this particular node just doesn't want to play.

I've tried node-mynodename.tpl.php, I tried node-view-mynodename.tpl.php. I've flushed the cache but no joy.

Using theme developer it insists that says the file it has used is called theme_views_view_field()or theme_text_formatter_default()

I wish I knew more about what's going on. I'm just trying to create another View like I have with several others that work fine, but not this one. I created several new CCK + Views but none of them work either...

Do you know what I'm missing?

Many thanks

Simon

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <strong> <code> <p> <img> <ul> <ol> <li> <h2> <h3> <h4> <b> <u> <i>
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.