ELIMINATE BLANK LINES OR HEADINGS WHEN THERE’S NO INFORMATION IN A FIELD - Aug 3rd, 2010


Dwelling asked the question and Dave came to the rescue. He suggested to start by experimenting with the PHP “if”
tag.



<?PHP if ($newsRecord['title']): ?>
Title: <?PHP echo $newsRecord['title'] ?>
<?PHP endif; ?>



Here’s one that was used in a multi record editor to eliminate the word “through” if there was no “end date”
and the heading :Reception” if that field was blank:



<?PHP foreach ($exhibitionsRecords as $record): ?>
<tr valign="top" align="center">
<td >
<span class="heading-text-bold"><?PHP echo $record['title'] ?></span><br />
<span class="body-text"> <?PHP echo $record['start_date'] ?>&nbsp;</span>
<span class="body-text"> <?PHP if ($record['end_date']): ?>Through&nbsp;<?PHP echo $record['end_date'] ?></span><br />
<?PHP endif; ?>
<?PHP if ($record['reception_date_and_time']): ?> <span class="heading-text-bold">Reception</span><br /><span
class="body-text"> <?PHP echo $record['reception_date_and_time'] ?> </span>
<?PHP endif; ?>
</td>
</tr>
<tr>
<td align="left" height="125" valign="top"><div class="body-text"><?PHP echo $record['content'] ?></div></td>
</tr> <tr>
<td align="center">
<!-- display image --> <?PHP foreach ($record['image'] as $upload): ?>
<?PHP if ($upload['hasThumbnail']): ?>
<img src="<?PHP echo $upload['thumbUrlPath'] ?>" width="<?PHP echo $upload['thumbWidth'] ?>" height="<?PHP echo
$upload['thumbHeight'] ?>" alt="" />
<?PHP elseif ($upload['isImage']): ?>
<img src="<?PHP echo $upload['urlPath'] ?>" width="<?PHP echo $upload['width'] ?>" height="<?PHP echo $upload['height']
?>" alt="" />
<?PHP else: ?>
<a class="special" href="<?PHP echo $upload['urlPath'] ?>">DOWNLOAD<?PHP echo $upload['filename'] ?></a>
<?PHP endif ?>
<div class="body-text-bold">
<?PHP echo $upload['info1']; ?><br />
<?PHP echo $upload['info2']; ?> </div></td>
<?PHP endforeach ?>



Basically you just put the field you want to test in between the brackets. Note that this won't display for blank -or-
zero.



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service