Hide html code if field is empty
Permalink Browser Info Environment
Hi Jordan,
I styled an item like:
Is it possible to hide the html code (<p></p> in this case) as well if the field for that item is empty?
Best
Torsten
I styled an item like:
<p><?php $item->intem_one->display(); ?></p>
Is it possible to hide the html code (<p></p> in this case) as well if the field for that item is empty?
Best
Torsten
Type: | Discussion |
---|---|
Status: | New |
Hi Dan,
when I use that code (exactly), it breaks my page. Is there something wrong with the php code?
Here is my code:
Best
Torsten
when I use that code (exactly), it breaks my page. Is there something wrong with the php code?
Here is my code:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?> <?php /* This block was made with Designer Content Pro. Visithttp://theblockery.com/dcp for documentation. */ ?> <div class="well"> <?php foreach ($controller->getRepeatingItems() as $item): ?> <h4><?php $item->name->display(); ?></h4> <?php if (!empty($item->info->getText()) { ?> <p><?php $item->info->display(); ?></p> <?php } ?> <p><?php $item->info2->display(); ?></p> <p> Tel: <?php $item->tel->display(); ?><br /> Fax: <?php $item->fax->display(); ?><br /> Link: <?php $item->link->display(); ?><br /> E-Mail: <a href="mailto:<?php $item->email->display(); ?>"><?php $item->email->display(); ?></a> </p>
Viewing 15 lines of 17 lines. View entire code block.
Best
Torsten
Hi Torsten,
My apologies. The use of empty() threw an error.
Try this instead:
getText() will return an empty string (resulting in false for the if statement) if the field was left blank. So empty() wasn't really necessary anyway.
Thanks,
Dan
My apologies. The use of empty() threw an error.
Try this instead:
<?php if ($item->info->getText()) { ?> <p><?php $item->info->display(); ?></p> <?php } ?>
getText() will return an empty string (resulting in false for the if statement) if the field was left blank. So empty() wasn't really necessary anyway.
Thanks,
Dan
Thanks - that works :)
Jordan is out today, but I can answer your question.
If "intem_one" is a textbox or textarea field, you can do this:
The various field types in DCP have several options for displaying/getting the content. We have API docs available athttp://theblockery.com/designer-content-pro/.... That should be helpful, but definitely let us know if you get hung up and have any other questions.
- Dan