Hiding fields if no content and layout issues

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

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

By gregThomas - July 17, 2013

Hi,

I think the problem is your missing a colon on the end of your if statement:

 <?php if ($lease_warehouseRecord['yard_sqm']): ?><li><?php echo htmlencode($lease_warehouseRecord['yard_sqm']); ?></li><?php endif; ?>

Let me know if you have any questions.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com