Drupal 6: How to quickly theme a view ?

Posted by Pierre-Jean Coudert on Stack Overflow See other posts from Stack Overflow or by Pierre-Jean Coudert
Published on 2008-09-16T22:02:57Z Indexed on 2010/05/30 9:12 UTC
Read the original article Hit count: 303

Filed under:
|
|
|
|

I've defined a view with the cck and view2 modules. I would like to quickly define a template specific to this view. Any tutorial or information on this ? What are the files I need to modify ?


Here are my findings: (Edited)

In fact there are two ways to theme a view : the "field" way and the "node" way. In "edit View", you can choose "Row style: Node", or "Row style: Fields".

  • with the "Node" way, you can create a node-contentname.tpl.php wich will be called for each node in the view. You'll have access to your cck field values with $field_name[0]['value']. (edit2) You can use node-view-viewname.tpl.php wich will be only called for each node displayed from this view.
  • with the "Field" way, you add a views-view-field--viewname--field-name-value.tpl.php for each field you want to theme individually.

Thanks to previous responses, I've used the following tools :

  • In the 'Basic Settings' block, the 'Theme: Information' to see all the different templates you can modify.
  • The Devel module's "Theme developer" to quickly find the field variable names.
  • View 2 documentation, especially the "Using Theme" page.

© Stack Overflow or respective owner

Related posts about php

Related posts about drupal