function views_preprocess_node

Same name in other branches
  1. 7.x-3.x views.module \views_preprocess_node()

A theme preprocess function to automatically allow view-based node templates if called from a view.

The 'modules/node.views.inc' file is a better place for this, but we haven't got a chance to load that file before Drupal builds the node portion of the theme registry.

File

./views.module, line 244

Code

function views_preprocess_node(&$vars) {
    // The 'view' attribute of the node is added in template_preprocess_views_view_row_node()
    if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) {
        $vars['view'] =& $vars['node']->view;
        $vars['template_files'][] = 'node-view-' . $vars['node']->view->name;
        if (!empty($vars['node']->view->current_display)) {
            $vars['template_files'][] = 'node-view-' . $vars['node']->view->name . '-' . $vars['node']->view->current_display;
        }
    }
}