Hiding fields if no content and layout issues

6 posts by 3 authors in: Forums > CMS Builder
Last Post: July 17, 2013   (RSS)

Hi Support

1.  I've checked your forum, but there's nothing that deals with hiding multiple fields in multiple columns if there is no data.  For example, for a real estate client, there may be one, two, three of four different areas with different sqm, yet other properties might only have one.  How do I hide potentially multiple fields in a listing.

2.  Is there any other way of forcing the content to a next line other than using <br>...the problem is that the <br> in the empty field is pushing the content down.

Code is attached.

<table class="footable">
 
<thead> 
 
<tr>
 
<th data-class="expand">Property</th>
<th>Location</th>
<th data-hide="phone,tablet">Area</th>
<th data-hide="phone,tablet">Size sqm</th>
<th data-hide="phone,tablet">Rent - $psm</th>
<th data-hide="phone">Details</th>
 
</tr></thead>
 
 
<?php foreach ($lease_warehouseRecords as $record): ?>
 
<tbody>
<tr>
 
<td valign="top" width="150"><?php echo $record['suburb'] ?> <br>
<?php echo htmlencode($record['address']) ?></td>
 
<td valign="top" width="60">
<?php echo $record['building_area_1'] ?><br>
<?php if ($record['building_area_2_sqm']): ?><?php echo $record['building_area_2'] ?><?php endif ?><br>
<?php if ($record['building_area_3_sqm']): ?><?php echo $record['building_area_3'] ?><?php endif ?><br>
<?php if ($record['building_area_4_sqm']): ?><?php echo $record['building_area_4'] ?><?php endif ?><br> </td>
<td valign="top">
 
<?php echo $record['building_area_1_sqm'] ?><br>
<?php echo $record['building_area_2_sqm'] ?><br>
<?php echo $record['building_area_3_sqm'] ?><br>
<?php echo $record['building_area_4_sqm'] ?><br></td>
 
 
<td valign="top" width="100">
<?php echo $record['building_area_1_rent_psm'] ?><br> 
<?php echo $record['building_area_2_rent_psm'] ?><br>
<?php echo $record['building_area_3_rent_psm'] ?></td>
  
 
<td valign="top"><?php echo $record['brief_intro'] ?><a href="<?php echo $record['_link'] ?>"> ||  more info</a></td></tr>
 
 
 
<?php endforeach ?>
<?php if (!$lease_warehouseRecords): ?>
  No records were found!<br/><br/>
  <?php endif ?>
</tbody>
</table>

The problem is it looks fine in PC mode, but when it goes to responsive mode, it's adding the line breaks/empty fields in the spacing of the responsive format in the mobile view which is what I want to get rid of.  Here's the weblink: http://www.fordland.com.au/list.php (resize it to mobile view and you can see what I'm talking about with regards to the extra space.

Thanks

By Toledoh - July 2, 2013

Maybe I'm not reading the question correctly, but if you include the break in if statement, the line return would only occur if there was a result.

ie.

<?php if ($record['building_area_2_sqm']): ?><?php echo $record['building_area_2'] ?><br /><?php endif ?>

Cheers,

Tim (toledoh.com.au)

By gregThomas - July 3, 2013

Hi,

Could you check if the field is blank, and then not display it, like you've done with building_area fields? For example:

<?php if($record['building_area_1_sqm']) :?><?php echo $record['building_area_1_sqm'] ?><br><?php endif; ?>

If the field had been left blank, the above if statement would return false and the field would not be displayed.

For the second point, Tim's suggestion for having the <br> inside of the if statement should stop the content being pushed down the page.

Let me know if you have any questions. 

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Perfect.  Thanks so much.

One more question:

How do I hide a list item if the field is empty on a detailed page?  For example, my code is:

<ol class="list-arrow">              
<li>Office:  <?php echo htmlencode($lease_warehouseRecord['office_production_sqm']) ?> sqm</li>              
<li>Warehouse:  <?php echo htmlencode($lease_warehouseRecord['warehouse_sqm']) ?> sqm</li>              
<li><strong>Total:  <?php echo htmlencode($lease_warehouseRecord['total_sqm_1']) ?> sqm</strong></li>              
<li>Yard:  <?php echo htmlencode($lease_warehouseRecord['yard_sqm']) ?> sqm</li>
</ul>

However, I'd rather not show the entire Yard list row if the Yard SQM is empty.  If I use the <?php if ($lease_warehouseRecord['yard_sqm']) ?><li><?php echo htmlencode($lease_warehouseRecord['yard_sqm']) ?></li><?php endif; ?>, nothing on the page displays.

Thanks