2

I am using d7 and views.

I've created a view tpl file specific to my view using the the file name of: views-view-fields--cameras.tpl.php

<?php 

foreach ($fields as $id => $field): ?>
<?php 
$output = '';
$output .=  $field->label_html;
$output .= '<table width=100% border=1>';
if($field->label_html == 'camera_brand_star:')
{
$output .= $field->wrapper_prefix;
$output .= '<tr><td>hello</td></tr>';
$output .= $field->wrapper_suffix;
}
else if($field->label_html == 'camera_price_star')
{
$output .= $field->wrapper_prefix;
$output .= '<tr><td>'.$field->content.'</td></tr>';
$output .= $field->wrapper_suffix;
}
else if($field->label_html == 'brand:')
{
$output .= $field->wrapper_prefix;
$output .= '<tr><td>'.$field->content.'</td></tr>';
$output .= $field->wrapper_suffix;
}

else
{
$output .= $field->wrapper_prefix;
//$output .= '<tr><td>'.$field->content.'</td></tr>';
$output .= $field->wrapper_suffix;
}
$output .= '</table>';
echo $output;
//echo $field->label_html;
?>
<?php endforeach; ?>

The if conditions are not working at all as its not printing any content. Only it prints the output of $output .= $field->label_html; What am I doing wrong?

1

Please provide the markup that's currently produced by this code. The PHP logic looks fine but it's not cleat if $field->label_html has a value that will trigger and of the if statements. As a bare minimum you should be getting:

<table width=100% border=1>
</table>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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