I am having trouble passing custom data through theme() to a custom callback and passing the data through to a tpl file. Here is my code:


function satb_schedule_theme() {
  return array(
    'satb_schedule_brackets' => array(
      'render element' => 'bracket',
      'variables' => array('bracket' => array()),
      'template' => 'satb_schedule_brackets',
      'path' => drupal_get_path('module', 'satb_schedule') . '/templates',

hook_menu item:

$items['tournaments/%/%/schedule/winner-bracket'] = array(
    'title' => 'Winner Bracket',
    'description' => 'View the winner brackets for this tournament.',
    'page callback' => 'satb_schedule_generate_bracket',
    'page arguments' => array(1, 2, '0'),
    'weight' => -16,
    'type' => MENU_LOCAL_TASK,
    'access arguments' => array('view tournament brackets'),

hook_menu item callback (satb_schedule_generate_bracket):

function satb_schedule_generate_bracket($nid, $product_id, $bracket_type) {
  $schedule = new SATBScheduleDisplay(array('nid' => $nid, 'product_id' => $product_id));
  return $schedule->getTournamentBracket($bracket_type);

This function generates an array of data. Inside of the method, data is gathered and returned through theme(), like so:

$output = theme('satb_schedule_brackets', array('bracket' => $brackets));
return $output;

In the template.php, I have this to modify and add variables for the template:

function satb_preprocess_satb_schedule_brackets($variables) {
  $brackets = $variables['bracket'];

  foreach($brackets as $key => $round) {
    switch ($key) {
      case 3:
        $classes = array('round', 'quarterfinal');
        $round_title = t('Quarter Finals');
      case 2:
        $classes = array('round', 'semifinal');
        $round_title = t('Semi-Finals');
      case 1:
        $classes = array('round', 'final');
        $round_title = t('Final');
        $classes = array('round');
        $round_title = t('Round @round_number', array('@round_number' => $key));

    $variables['bracket'][$key]['data'] = array('classes' => implode(' ', $classes), 'round-title' => $round_title);

  $vars['bracket'] = $variables['bracket'];
  $vars['tournament_title'] = 'Just a test';
  return $vars;

My custom tpl is loaded (I can see the static HTML in there as a test and print static vars) however, my modifications don't seem to get passed to the template.

For example, if I do print $tournament_name;, its null. If I do print $bracket['tournament_title']- it appears, but I don't want to access variables like that because that's messy, and, it should respect the vars I am adding to the vars array.

What am I missing here? The classes and titles I am adding in the preprocess are also missing in the $bracket element in the TPL. The $vars has them, but the TPL does not.

1 Answer 1


Doh. $variables is passed by reference. I always forget this in template.php:

function satb_preprocess_satb_schedule_brackets(&$variables) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.