function template_preprocess

Adds a default set of helper variables for variable processors and templates.

This function is called for theme hooks implemented as templates only, not for theme hooks implemented as functions. This preprocess function is the first in the sequence of preprocessing and processing functions that is called when preparing variables for a template. See theme() for more details about the full sequence.

See also

theme()

template_process()

1 call to template_preprocess()
theme in drupal/core/includes/theme.inc
Generates themed output.
2 string references to 'template_preprocess'
user_user_login in drupal/core/modules/user/user.module
Implements hook_user_login().
user_user_logout in drupal/core/modules/user/user.module
Implements hook_user_logout().

File

drupal/core/includes/theme.inc, line 2465
The theme system, which controls the output of Drupal.

Code

function template_preprocess(&$variables, $hook) {
  global $user;
  static $count = array(), $default_attributes;

  // Track run count for each hook to provide zebra striping.
  // See "template_preprocess_block()" which provides the same feature specific to blocks.
  $count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $count[$hook] : 1;
  $variables['zebra'] = $count[$hook] % 2 ? 'odd' : 'even';
  $variables['id'] = $count[$hook]++;

  // Tell all templates where they are located.
  $variables['directory'] = path_to_theme();

  // Merge in variables that don't depend on hook and don't change during a
  // single page request.
  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['default_variables'] =& drupal_static(__FUNCTION__);
  }
  $default_variables =& $drupal_static_fast['default_variables'];
  if (!isset($default_variables)) {
    $default_variables = _template_preprocess_default_variables();
  }
  if (!isset($default_attributes)) {
    $default_attributes = new Attribute(array(
      'class' => array(),
    ));
  }
  $variables += $default_variables + array(
    'attributes' => clone $default_attributes,
    'title_attributes' => clone $default_attributes,
    'content_attributes' => clone $default_attributes,
  );

  // Initialize html class attribute for the current hook.
  $variables['attributes']['class'][] = drupal_html_class($hook);
}