You are here

function _phptemplate_default_variables in Drupal 4

Same name and namespace in other branches
  1. 5 themes/engines/phptemplate/phptemplate.engine \_phptemplate_default_variables()

Adds additional helper variables to all templates.

Counts how many times certain hooks have been called. Sidebar left / right are special cases.

Parameters

$hook: The name of the theme function being executed.

$variables: A sequential array of variables passed to the theme function.

1 call to _phptemplate_default_variables()
_phptemplate_callback in themes/engines/phptemplate/phptemplate.engine
Execute a template engine call.

File

themes/engines/phptemplate/phptemplate.engine, line 86
Handles integration of templates written in pure php with the Drupal theme system.

Code

function _phptemplate_default_variables($hook, $variables) {
  global $theme, $sidebar_indicator;
  static $count = array();
  $count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $count[$hook] : 1;
  $variables['zebra'] = $count[$hook] % 2 ? 'odd' : 'even';
  $variables['id'] = $count[$hook]++;
  if ($hook == 'block') {
    $count['block_counter'][$sidebar_indicator] = isset($count['block_counter'][$sidebar_indicator]) && is_int($count['block_counter'][$sidebar_indicator]) ? $count['block_counter'][$sidebar_indicator] : 1;
    $variables['block_zebra'] = $count['block_counter'][$sidebar_indicator] % 2 ? 'odd' : 'even';
    $variables['block_id'] = $count['block_counter'][$sidebar_indicator]++;
  }
  elseif ($hook == 'page') {
    $regions = system_region_list($theme);

    // Load all region content assigned via blocks.
    foreach (array_keys($regions) as $region) {

      // Skip blocks in this region that have already been loaded.
      // This pre-loading is necessary because phptemplate uses variable names different from
      // the region names, e.g., 'sidebar_left' instead of 'left'.
      if (!in_array($region, array(
        'left',
        'right',
        'footer',
      ))) {
        isset($variables[$region]) ? $variables[$region] .= theme('blocks', $region) : ($variables[$region] = theme('blocks', $region));
      }
    }
  }

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