Is there a way to theme a view without using the wizard? I ask because I see no wizard for 6.x, so I'm pretty much guessing what code I need to implement.

I was poking around in modules/views/themes and looking at the View_views_view list but I don't think this is what I'm looking for.

Thanks,
NB

Comments

Lioz’s picture

subscribing...:)

waynesmifff’s picture

Subscribing

ericcorriel’s picture

subscribing

theactiveme’s picture

interested as well

jmaties’s picture

subscribing

WorldFallz’s picture

There's a new function "Theme: Information" in the views options screen-- it provides the same type of info the views wizard used to. Also, you can use the devel module's theme developer function to help you theme views.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

greg.harvey’s picture

That's all very well, but what if I don't want literally *hundreds* of tpl files cluttering up my theme? Can I still use phptemplate functions in template.php? And if so, what is the naming convention?

I might create this as a support request under the views module. It is more likely to get attention.

--
http://www.drupaler.co.uk/

greg.harvey’s picture

Answered my own question. I was browsing the Views code when I came across the _views_theme_functions() function which appeared to allow themes to invoke fine-grained theming hooks. It does! Read this:
http://www.agileapproach.com/blog-entry/theming-views-drupal-6

--
http://www.drupaler.co.uk/

WorldFallz’s picture

ah.... excellent article... thanks for posting it back to the thread.

other than organization, do you have any idea of the relative merits of theming views with tpl files versus functions?

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

greg.harvey’s picture

I don't think there are any particular merits, besides organisation. I imagine there is a slight performance gain to be had in NOT including a bunch of tpl files, but I'm only guessing and caching would probably negate any real gains on that front anyway. Generally speaking most people should use the tpl files, but this is a useful trick for *developers* to be aware of. =)

Btw, there seem to be some mistakes in that article - some hooks have either changed or were incorrectly documented. To get a list of available hooks you should browse to modules/views/theme/theme.inc (or wherever your modules are) and output the $themes variable in the _views_theme_functions() function at the start of that file - here's an example with the Devel module installed:

function _views_theme_functions($hook, $view, $display = NULL) {
  $themes = array();

  if ($display) {
    $themes[] = $hook . '__' . $view->name . '__' . $display->id;
    $themes[] = $hook . '__' . $display->id;
    if ($display->id != $display->display_plugin) {
      $themes[] = $hook . '__' . $view->name . '__' . $display->display_plugin;
      $themes[] = $hook . '__' . $display->display_plugin;
    }
  }
  $themes[] = $hook . '__' . $view->name;
  $themes[] = $hook;

  //what are the available hooks?
  dsm($themes);
  return $themes;
}

Sub for this if you don't have Devel:

  //what are the available hooks?
  print_r($themes);

AFAIK, then you'll get the actual list of hooks the Views module is expecting to look for. Prepend them with themename_ to use them in template.php.

--
http://www.drupaler.co.uk/

greg.harvey’s picture

Please note, the Views developers DO NOT WANT PEOPLE TO USE THIS!
http://drupal.org/node/303438#comment-992759

I will anyway, because in my case using tpl files would be too difficult to manage, but this should be used only in extreme examples. Most people should use templates, as originally answered by WorldFallz.

--
http://www.drupaler.co.uk/

greg.harvey’s picture

Ok. I've batted this around for a day now, and had input from various quarters, including Merlin himself, and I wrote this blog post to put all the research in one place - hope it's useful:
http://www.drupaler.co.uk/blog/theming-views-drupal-6x/67

=)

--
http://www.drupaler.co.uk/