//in template.php----------------------------


function phptemplate_views_view_list_promotion_box($view, $nodes, $type) {
  /*
  $fields = _views_get_fields();
  drupal_set_message('<PRE>phptemplate_views_view_list_promotion_box(): $fields: '.print_r($fields, 1).'</PRE>');
  drupal_set_message('<PRE>phptemplate_views_view_list_promotion_box(): $view: '.print_r($view, 1).'</PRE>');
  drupal_set_message('<PRE>phptemplate_views_view_list_promotion_box(): $nodes: '.print_r($nodes, 1).'</PRE>');
  drupal_set_message('<PRE>phptemplate_views_view_list_promotion_box(): $type: '.print_r($type, 1).'</PRE>');
  */
  $taken = array();

  // Group our nodes
  $set = array();
  foreach($nodes as $node)
  {
   $set[$node->node_title][] = $node;
  }

  // Set up the fields in nicely named chunks.
  foreach ($view->field as $id => $field) {
    $field_name = $field['field'];
    if (isset($taken[$field_name])) {
      $field_name = $field['queryname'];
    }
    $taken[$field_name] = true;
    $field_names[$id] = $field_name;
  }

  // Set up some variables that won't change.
  $base_vars = array(
    'view' => $view,
    'view_type' => $type,
  );

  $output = "{\n";
  $j = 0;
  foreach ($set as $label => $nodes)
  {
   if($j > 0)
   {
    $output .= ",\n";
   }
   ++$j;
   $items = array();
   foreach ($nodes as $i => $node)
   {
    $vars = $base_vars;
    $vars['node'] = $node;
    $vars['count'] = $i;
    $vars['stripe'] = $i % 2 ? 'even' : 'odd';
    foreach ($view->field as $id => $field)
    {
     $name = $field_names[$id];
     $vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
     if (isset($field['label']))
     {
      $vars[$name . '_label'] = $field['label'];
     }
    }
    $items[] = _phptemplate_callback('views-list-promotion_box', $vars);
   }
   if ($items)
   {
    //print('<PRE> '); var_dump($items); print(' </PRE>');
    //print('<PRE> '); var_dump($label); print(' </PRE>');
    $output .= '"'.$j.'": '.theme('promotion_box_item_list', $items, $label);
   }
  }
  $output .= "}\n";
  return $output;
}

function phptemplate_promotion_box_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
  $output = '';

  if (!empty($items)) {
    $output .= "\n";
    foreach ($items as $item) {
      $attributes = array();
      $children = array();
      if (is_array($item)) {
        foreach ($item as $key => $value) {
          if ($key == 'data') {
            $data = $value;
          }
          elseif ($key == 'children') {
            $children = $value;
          }
          else {
            $attributes[$key] = $value;
          }
        }
      }
      else {
        $data = $item;
      }
      if (count($children) > 0) {
        $data .= phptemplate_promotion_box_item_list($children, NULL, $type, $attributes); // Render nested list
      }
      $output .= $data ;
    }
  }
  return $output;
}

//end of template.php---------------------------------------
//in views-list-promotion_box.tpl.php--------------------------
<?php 
 drupal_add_css(path_to_theme() .'/views-list-promotion_box.css');
 print json_encode
 (
  Array
  (
   'title' => $title,
   'field_promo_category_value' => $field_promo_category_value,
   'body' => $body,
   'field_promo_article_nid' => $field_promo_article_nid,
   'field_promo_url_value' => $field_promo_url_value,
   'field_promo_image_fid' => $field_promo_image_fid
  )
 );
?>
//end of views-list-promotion_box.tpl.php--------------------------
//old views-list-promotion_box.tpl.php---------------------------------------------
<?php 
/**
 * views template to output one 'row' of a view.
 * This code was generated by the views theming wizard
 * Date: Wed, 2008-06-04 10:23
 * View: promotion_box
 *
 * Variables available:
 * $view -- the entire view object. Important parts of this object are
 *   promotion_box, .
 * $view_type -- The type of the view. Probably 'page' or 'block' but could
 *   also be 'embed' or other string passed in from a custom view creator.
 * $node -- the raw data. This is not a real node object, but will contain
 *   the nid as well as other support fields that might be necessary.
 * $count -- the current row in the view (not TOTAL but for this page) starting
 *   from 0.
 * $stripe -- 'odd' or 'even', alternating. * $title -- Display the title of the node.
 * $title_label -- The assigned label for $title
 * $field_promo_category_value -- 
 * $field_promo_category_value_label -- The assigned label for $field_promo_category_value
 * $body -- Display the Main Content.
 * $body_label -- The assigned label for $body
 * $field_promo_article_nid -- 
 * $field_promo_article_nid_label -- The assigned label for $field_promo_article_nid
 * $field_promo_url_value -- 
 * $field_promo_url_value_label -- The assigned label for $field_promo_url_value
 * $field_promo_image_fid -- 
 * $field_promo_image_fid_label -- The assigned label for $field_promo_image_fid
 *
 * This function goes in your views-list-promotion_box.tpl.php file
 */
 
 
 //now we add the stylesheet...
  drupal_add_css(path_to_theme() .'/views-list-promotion_box.css');
  
  ?>
<div class="view-label view-field-title">
  <?php print $title_label ?>
</div>
<div class="view-field view-data-title">
  <?php print $title?>
</div>

<div class="view-label view-field-field-promo-category-value">
  <?php print $field_promo_category_value_label ?>
</div>
<div class="view-field view-data-field-promo-category-value">
  <?php print $field_promo_category_value?>
</div>

<div class="view-label view-field-body">
  <?php print $body_label ?>
</div>
<div class="view-field view-data-body">
  <?php print $body?>
</div>

<div class="view-label view-field-field-promo-article-nid">
  <?php print $field_promo_article_nid_label ?>
</div>
<div class="view-field view-data-field-promo-article-nid">
  <?php print $field_promo_article_nid?>
</div>

<div class="view-label view-field-field-promo-url-value">
  <?php print $field_promo_url_value_label ?>
</div>
<div class="view-field view-data-field-promo-url-value">
  <?php print $field_promo_url_value?>
</div>

<div class="view-label view-field-field-promo-image-fid">
  <?php print $field_promo_image_fid_label ?>
</div>
<div class="view-field view-data-field-promo-image-fid">
  <?php print $field_promo_image_fid?>
</div>
//end of old views-list-promotion_box.tpl.php