Archive for September, 2011

Drupal 7: Get the tpl.php name of a certain View

I was trying to theme a certain view in a D7 site since I couldn’t get Views to do what I needed without using my own PHP and jQuery.

It took me ages to track down what name to use in the tpl file for my theme. The easiest way of finding out what tpl.php name to use, either for a single view, type of view (e.g. unformatted list) or all views is to go into:

Structure > View > Edit your view

Then under Advanced of the right you will find a “Theme: Information” link that gives you extensive information on the files in use. Enjoy.

Tags:

Drupal 7 doesn’t use tpl files for nodes or content types

If you are copying the default page.tpl.php to use for either a specific node or a specific content type but Drupal is ignoring it there are usually two main reasons:

  1. tpl file name
    If you are used to the D6 naming conventions, be aware it has changed in D7. The new naming conventions are here
  2. Preprocess function
    You may have forgotten to put a preprocess hook in your theme file. For example I have this in most of my Zen sub themes:
    function MYTHEME_preprocess_page(&$variables, $hook) {
    //some other stuff
    if (isset($variables['node']))
    {
    $variables['theme_hook_suggestions'][] = 'page__type__'. $variables['node']->type;
    $variables['theme_hook_suggestions'][] = "page__node__" . $variables['node']->nid;
    }

    }

  3. Hope that helps