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> </td>";
}
print "</tr></table><br />";
}
}
}}
?>
| Comment | File | Size | Author |
|---|---|---|---|
| Image2.jpg | 57.87 KB | Anonymous (not verified) | |
| Image1.jpg | 42.16 KB | Anonymous (not verified) |
Comments
Comment #1
jrglasgow commentedcould you include a list of the variables available, that would be most useful in helping you fix tour problem.
Comment #2
Anonymous (not verified) commentedMany 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
Comment #3
Anonymous (not verified) commentedWell , 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
Comment #4
Anonymous (not verified) commented