Display field list with icon

Currently I am trying to reconstruct the module code by adding Icons next to each field in the listing. This is the code below.

<?php
if (empty($item->webpage)) :
?>

<td class=“peoplename”><?php echo $item->name; ?></td>
<td class=“peopleemailto”><a href=“mailto:<?php echo $item->email_to; ?>”><?php echo $item->email_to; ?></a></td>
<td class=“peopletelephone”><?php echo $item->telephone; ?></td>
<td class=“peoplewebpage”><a href=“<?php echo JRoute::_(‘’); ?>”><img src=“/images/powered_by.png”></a></td>

{?php endif; ?>

My objective is to display an icon/image next to each field list that has a webpage only. Otherwise it display only the list without image.

I presume you want the opposite of what you showed us then, that if a webpage is set, show the <td> contents? If so try either of these 2 alterations to your first line:


if ($item->webpage) :


if( isset($item->webpage)) :

Yes I want to display an icon next to each name field if they have an extended website where the field name is “webpage”.

<?php
if (isset($item->webpage)) :
?>

<td class=“peoplename”><?php echo $item->name; ?></td>
<td class=“peopleemailto”><a href=“mailto:<?php echo $item->email_to; ?>”><?php echo $item->email_to; ?></a></td>
<td class=“peopletelephone”><?php echo $item->telephone; ?></td>
<?php
else
?>
<td class=“peoplename”><?php echo $item->name; ?></td>
<td class=“peopleemailto”><a href=“mailto:<?php echo $item->email_to; ?>”><?php echo $item->email_to; ?></a></td>
<td class=“peopletelephone”><?php echo $item->telephone; ?></td>
<td class=“peoplewebpage”><a href=“<?php echo JRoute::_(‘’); ?>”><img src=“/images/powered_by.png”></a></td>
<?php endif; ?>

Isolate that which changes.

If name, mail, phone are common to both cases then can you not get on and print them anyway?



<td class="peoplename"><?php echo $item->name; ?></td>
<td class="peopleemailto"><a href="mailto?php echo $item->email_to; ?>"><?php echo $item->email_to; ?></a></td>
<td class="peopletelephone"><?php echo $item->telephone; ?></td>

<!-- only have this one condition -->

<?php if (isset($item->webpage)) : ?>
<td class="peoplewebpage"><a href="<?php echo JRoute::_(''); ?>"><img src="/images/powered_by.png"></a></td>
<?php endif; ?>


Top tip: To format code on here, wrap your php code in the tags [ php ] [ /php ] (without the spaces)