views:

40951

answers:

7

I've defined a view with the CCK and View 2 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.
+16  A: 

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']
  • 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.
Pierre-Jean Coudert
+9  A: 

A quick way to find the template files you can create and modify for a view in Views 2.0 is to:

  1. Edit the view
  2. Select the style (e.g. page, block, default)
  3. In the 'Basic Settings' block click on 'Theme: Information' to see all the different templates you can modify.
calebbrown
+9  A: 

The Devel module's "Theme developer" feature is handy for seeing what template files Drupal is looking for when it goes to theme something. See the screenshot on that page for an example.

Garrett Albright
+4  A: 

My shortcut option.

  1. Go to theme.inc file in YOUR_MODULE_DIR/views/theme/ folder.

  2. In the _views_theme_functions function print the $themes variable or put a breakpoint on the last line of the function to see the content of the variable.

Just convert views_view to views-view and __ to -- and add your template extension to get desired file name.

For example if an element of the $themes array is views_view__test_view__block (where test_view is the name of your view) then the name of the template file would be views-view--test_view--block.tpl.php.

mun2mun
+2  A: 

for me block-views-myViewName-myBlockId.tpl.php works

svassr
+2  A: 

In my opinion the simplest way to decide which template file to use for theming the views is : 1) Click on admin/build/views/edit/ViewName -> Basic Settings -> Theme

Clicking this would list all the possible template files. Highlighted (File names in Bold) files indicate which template file is being used to do theme what part of the view. After incorporating the required changes in the relevant view template file RESCAN .. now you should be able to see the changed template file highlighted .

Saurabh
+3  A: 

You should also check out Semantic Views. For simple Views theming, it is really handy.

David Eads