I wonder if you could cast an eye over the following code. it is from a contemplate 5.x-2.04, but the code no longer works under 6.x-1.0. In fact its the only template that doesnt work

I know its not the most elegant of codes, i cobbled it together from a number of sources, but it did work :)

Basically it takes the array and formats it in 3 columns with changing colours (image1.jpg). Now all i get is one column and only the first item of the array repeated image2.jpg). Is this due to changes in Drupal? Contemplate? or my poor coding ?

Any help would be appreciated as this is one of the last things i need to fix before I can take the drupal 6 site live

<?php
foreach ((array)$field_book_title as $item) {
if(!empty($item['view'])&& $item['view'] != " <br />"){
echo"<font size=\"3\" color=\"#627A8D\"><strong>Books Mentioned in:</strong></font>";

$field_book_title_col = preg_split("[<br />]", $field_book_title[0]['view']);

$columns = 3;

//alternate row colour
$color1 = "#dce6ef";
$color2 = "#ebf3f9"; 
$row_count = "0";  

for ($p=0; $p<count($field_book_title_col); $p++) {
                
        // Start of table or line?
        if ($p==0) { // Start of table
                print "<table align=\"center\" width=\"90%\" border=0><tr>";

//alternate row colour
$row_color = ($row_count % 2) ? $color1 : $color2; 

        } elseif ($p%$columns == 0) { // Start of row

//alternate row colour
$row_color = ($row_count % 2) ? $color1 : $color2; 
                print "<tr>";
               
        }

        print "<td align=\"center\" width=\"33%\"  

bgcolor=\"$row_color\">".htmlspecialchars($field_book_title_col[$p])."</td>";

        // End of table or line?
        if (($p+1)%$columns == 0) { // End of row
                print "</tr>";

//alternate row colour
    $row_count++;

        }
        if ($p==count($field_book_title_col)-1) { // End of table
                $empty = $columns - (count($field_book_title_col)%$columns) ;
                if ($empty != $columns) {
                        print "<td colspan=$empty>&nbsp;</td>";
                        }
                print "</tr></table><br />";
        }
}

}}
?>

CommentFileSizeAuthor
Image2.jpg57.87 KBAnonymous (not verified)
Image1.jpg42.16 KBAnonymous (not verified)

Comments

jrglasgow’s picture

could you include a list of the variables available, that would be most useful in helping you fix tour problem.

Anonymous’s picture

Many thanks for the reply. For the issue in hand the only real variable is $field_book_title the rest are created in the template , so I assume what you are looking for is the associated Body Variables for field_book_title - The resultant output in the sample data is "Mistress of the Empire" which is one of many in the array

$node->field_book_title (array) 
$node->field_book_title[0] (array) 
$node->field_book_title[0]['value'] ** 
           128 
$node->field_book_title[0]['view'] 
           Mistress of the Empire 
$node->content['field_book_title'] (array) 
$node->content['field_book_title']['#type_name'] 
         encyclopedia 
$node->content['field_book_title']['#context'] 
         full 
$node->content['field_book_title']['#field_name'] 
         field_book_title 
$node->content['field_book_title']['#post_render'] (array) 
$node->content['field_book_title']['#post_render'][0] 
        content_field_wrapper_post_render 
$node->content['field_book_title']['#weight'] 
        5 
$node->content['field_book_title']['field'] (array) 
$node->content['field_book_title']['field']['#description'] (NULL) 
$node->content['field_book_title']['field']['items'] (array) 
$node->content['field_book_title']['field']['items'][0] (array) 
$node->content['field_book_title']['field']['items'][0]['#formatter'] 
        default 
$node->content['field_book_title']['field']['items'][0]['#node'] 
        ** RECURSION ** 
$node->content['field_book_title']['field']['items'][0]['#type_name'] 
        encyclopedia 
$node->content['field_book_title']['field']['items'][0]['#field_name'] 
        field_book_title 
$node->content['field_book_title']['field']['items'][0]['#weight'] (integer) 
       0 
$node->content['field_book_title']['field']['items'][0]['#theme'] 
       content_taxonomy_formatter_default 
$node->content['field_book_title']['field']['items'][0]['#item'] (array) 
$node->content['field_book_title']['field']['items'][0]['#item']['value'] ** 
       128 
$node->content['field_book_title']['field']['items'][0]['#item']['#delta'] (integer) 
        0 
$node->content['field_book_title']['field']['items'][0]['#title'] (NULL) 
$node->content['field_book_title']['field']['items'][0]['#description'] (NULL) 
$node->content['field_book_title']['field']['items'][0]['#theme_used'] (boolean) 
        TRUE 
$node->content['field_book_title']['field']['items'][0]['#printed'] (boolean) 
        TRUE 
$node->content['field_book_title']['field']['items'][0]['#type'] (NULL) 
$node->content['field_book_title']['field']['items'][0]['#value'] (NULL) 
$node->content['field_book_title']['field']['items'][0]['#prefix'] (NULL) 
$node->content['field_book_title']['field']['items'][0]['#suffix'] (NULL) 
$node->content['field_book_title']['field']['items'][0]['#children'] 
        Mistress of the Empire 
$node->content['field_book_title']['field']['items']['#title'] (NULL) 
$node->content['field_book_title']['field']['items']['#description'] (NULL) 
$node->content['field_book_title']['field']['items']['#children'] 
        Mistress of the Empire 
$node->content['field_book_title']['field']['items']['#printed'] (boolean) 
        TRUE 
$node->content['field_book_title']['field']['#single'] (boolean) 
        TRUE 
$node->content['field_book_title']['field']['#attributes'] (array) 
$node->content['field_book_title']['field']['#required'] (boolean) 
         FALSE 
$node->content['field_book_title']['field']['#parents'] (array) 
$node->content['field_book_title']['field']['#tree'] (boolean) 
         FALSE 
$node->content['field_book_title']['field']['#context'] 
         full 
$node->content['field_book_title']['field']['#page'] (boolean) 
        TRUE 
$node->content['field_book_title']['field']['#field_name'] 
        field_book_title 
$node->content['field_book_title']['field']['#title'] 
        Book Title 
$node->content['field_book_title']['field']['#access'] (boolean) 
       TRUE 
$node->content['field_book_title']['field']['#label_display'] 
       above 
$node->content['field_book_title']['field']['#teaser'] (boolean) 
       FALSE 
$node->content['field_book_title']['field']['#node'] 
       ** RECURSION ** 
$node->content['field_book_title']['field']['#type'] 
      content_field 
$node->content['field_book_title']['field']['#children'] 
      Mistress of the Empire 
$node->content['field_book_title']['field']['#printed'] (boolean) 
      TRUE 
$node->content['field_book_title']['#title'] (NULL) 
$node->content['field_book_title']['#description'] (NULL) 
$node->content['field_book_title']['#children'] 
      <div class="field field-type-content-taxonomy field-field-book-title"> <div class="field-label">Book Title:&nbsp;</div> <div class="field-items"> <div class="field-item odd"> Mistress of the Empire </div> </div> </div> 
$node->content['field_book_title']['#printed'] (boolean) 
      TRUE 
Anonymous’s picture

Status: Fixed » Active

Well , i finally found a solution that worked, almost turned the code upside down. Why it worked in D5 still amazes me as looking at it, it did in D6 what I had told it to do in D5. I guess this is a case of 2 wrongs making a right, my code being wrong and something else that allowed my code to work :)

EDIT: Added the new working code that creates a three column list with alternating colour rows

<?php

if(!empty($field_book_title)){
echo"<font size=\"3\" color=\"#627A8D\"><strong>Books Mentioned In:</strong></font><br />";
$columns = 3;

//alternate row colour
$color1 = "#dce6ef";
$color2 = "#ebf3f9"; 
$row_count = "0"; 
$row_color = $color1;

for ($p=0; $p<count($field_book_title); $p++) {

$field_book_title_name = $node->field_book_title[$p]['view']; 

        // Start of table or line?
        if ($p==0) { // Start of table
                print "<table align=\"center\" width=\"90%\" border=0><tr>";

//alternate row colour
$row_color = ($row_count % 2) ? $color1 : $color2; 

        }

        elseif ($p%$columns == 0) { // Start of row

//alternate row colour
$row_color = ($row_count % 2) ? $color1 : $color2; 

                print "<tr>";
        }

              echo"<td align=\"center\" width=\"33%\" bgcolor=\"$row_color\">";   
              echo $field_book_title_name;
              echo"</td>";

        // End of table or line?
        if (($p+1)%$columns == 0) { // End of row
                print "</tr>";

//alternate row colour
    $row_count++;

        }

        if ($p==count($field_book_title)-1) { // End of table
                $empty = $columns - (count($field_book_title)%$columns) ;
                if ($empty != $columns) {
                        print "<td colspan=$empty>&nbsp;</td>";
                        }
                print "</tr></table>";
        }
    }
}

?>


Anonymous’s picture

Status: Active » Fixed

Status: Active » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.