Only display if completed [SOLVED]

More
12 years 8 months ago #17518 by webfooted
Hi there

I'm setting up a custom item.php template calling the fields directly to the template as per this post: www.flexicontent.org/forum/index ... =viewtopic

That's working great, but I would now like to set it so that fields only display if they have something entered in them (and aren't displayed if they're blank).

For example I've got this bit of code
Code:
<h3>Awards</h3> <table> <tr> <td><?php echo $this->fields['awardlogo']->display; ?></td> <td><?php echo $this->fields['awards']->display; ?></td> </tr> </table>
and I would only like it to display if there is some content in the 'awards' field.

If someone could point me in the right direction I'd be very grateful!

Cheers, Emily

Please Log in or Create an account to join the conversation.

More
12 years 8 months ago #17521 by pabro
Hi, try this:
Code:
<h3>Awards</h3> <table> <tr> <td><?php $awardlogo = $this->fields['awardlogo']->display; if ($awardlogo != '') { echo $awardlogo; } ?></td> <td><?php $awards = $this->fields['awards']->display; if ($awards != "") { echo $awards; } ?></td> </tr> </table>

Please Log in or Create an account to join the conversation.

More
12 years 8 months ago #17522 by webfooted
Thanks pabro, I really appreciate your help.

What I would like is to only display that whole block (including the h3 and table) if something has been entered into awards. Does that make sense?

Please Log in or Create an account to join the conversation.

More
12 years 8 months ago #17524 by ggppdk
Place your code inside between these 2 lines:
Code:
<?php if ($this->fields['awards']->display) : ?> <?php endif; ?>

In the above code i had one more parenthesis than needed i updated it ...

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
12 years 8 months ago #17526 by pabro
So, now the whole block will only display if "awards" is not empty ;)
Code:
<?php $awardlogo = $this->fields['awardslogo']->display; $awards = $this->fields['awards']->display; if ($awards != "") { echo "<h3>Awards</h3> <table> <tr> <td>$awardlogo</td> <td>$awards</td> <tr> </table>";} ?>

Please Log in or Create an account to join the conversation.

More
12 years 8 months ago #17528 by webfooted

pabro wrote: So, now the whole block will only display if "awards" is not empty ;)

Code:
<?php $awardlogo = $this->fields['awardslogo']->display; $awards = $this->fields['awards']->display; if ($awards != "") { echo "<h3>Awards</h3> <table> <tr> <td>$awardlogo</td> <td>$awards</td> <tr> </table>";} ?>


Very cool, thanks Pabro - that's exactly what I need. Thanks so much for your help.
Cheers, Emily

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.276 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline