• Register or
  • Sign In
    • Forgot your password?
    • Forgot your username?
    Or sign in with your account on:
    Facebook
    Twitter
    Google
    LinkedIn

K2 | The powerful content extension for Joomla! developed by JoomlaWorks

  • home
  • about
  • blog
  • documentation
  • extend K2
  • showcase
  • community
  • demo
The 'de facto' content solution for Joomla! professionals!
  • Index
  • Recent Topics
  • Search
Welcome, Guest

To post messages, you need to login first.
K2 Community Forum
K2 Community Forum
New to K2? Ask here first!

Hide individual Extra Field if empty
(1 viewing) (1) Guest
Reply Topic
New Topic
  • Page:
  • 1

TOPIC: Hide individual Extra Field if empty

Hide individual Extra Field if empty 1 year, 4 months ago #6974

  • Wesley
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 12
Sorry for a noob question and one that has been brought up so many times but I've tried all that I've read and it's not working.

In my template I don't have the Extra Fields at the bottom but instead are separated out individually in different areas of the template and I call them with:
<?php $custom = $this->item->extra_fields; echo $custom[2]->value; ?>

This works fine but I'm not able to hide these if empty. What if statement would I use?
<?php if(What Would Go Here) ?>
<?php $custom = $this->item->extra_fields; echo $custom[2]->value; ?>
<?php endif; ?>


Thank you!
Reply Quote

Re: Hide individual Extra Field if empty 1 year, 4 months ago #6976

  • William White
  • ( Moderator )
  • OFFLINE
  • Moderator
  • Posts: 3551
something like
if(!empty($str))
might just do the trick
For better answers, please include urls to your live site.
williamwhitejr.com/index.php/k2-support/...it-a-support-request
Reply Quote

Re: Hide individual Extra Field if empty 1 year, 4 months ago #6977

  • Wesley
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 12
Thanks for the reply, I tried that but it's still showing, I may be doing something wrong though.

I've added to the code in my example above, the end result will have the extrafield wrapped in a span and wording before it. When the field is empty I was needing to hide the span and wording. This is currently what I have:
<?php if(!empty($str)) ?>
Sub Title:<br />
<span class="itemSubTitle">
<?php $custom = $this->item->extra_fields; echo $custom[2]->value; ?>
</span>
<?php endif; ?>


Thanks again!
Last Edit: 1 year, 4 months ago by Wesley.
Reply Quote

Re: Hide individual Extra Field if empty 1 year, 4 months ago #6982

  • William White
  • ( Moderator )
  • OFFLINE
  • Moderator
  • Posts: 3551
try changin $str to $custom[2]->value
the code i send was for an illustration
Play around with it a bit, i havent tested
For better answers, please include urls to your live site.
williamwhitejr.com/index.php/k2-support/...it-a-support-request
Reply Quote

Re: Hide individual Extra Field if empty 1 year, 3 months ago #8347

  • Julie
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Wesley, were you able to figure this one out? I need to do this too.
Reply Quote

Re: Hide individual Extra Field if empty 1 year, 3 months ago #8353

  • Josh
  • ( User )
  • OFFLINE
  • Senior Boarder
  • Posts: 49
To display extra fields individually and in different places on the page I used this post..

getk2.org/documentation/tips-a-tricks/it...fic-extra-field-data

The to hide them again I use..

<?php if($extrafields['94'] != "") { ?>
<strong>Other Date Info:</strong>
<?php echo $extrafields[94];?>
<?php } ?>

I'm not great at php but this seems to do it. I believe this hides everything unless there is a value.
Last Edit: 1 year, 3 months ago by Josh.
Reply Quote

Re: Hide individual Extra Field if empty 11 months, 2 weeks ago #13419

  • CHAR
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I'm experiencing the same thing... I want to hide the empty extra field and I tried countless ways but no success. Below is my code... What should be changed/added/deleted?


<ul>
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
Reply Quote

Re: Hide individual Extra Field if empty 10 months, 2 weeks ago #158834

  • ysva
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
This bugged the hell out of me. I've posted a solution here:

getk2.org/community/New-to-K2-Ask-here-f...ate-css-class-solved
Reply Quote
Reply Topic
New Topic
  • Page:
  • 1
K2 Community Forum
K2 Community Forum
New to K2? Ask here first!
Find this topic helpful? Why not share it with others?
Tweet
Powered by Kunena
Time to create page: 0.36 seconds
Advertisement
  • Contact us
  • Join the K2 Expert Companies list
  • Privacy Policy
back to top
Copyright © 2006 - 2013 JoomlaWorks Ltd.. All rights reserved. K2 is a joint project by JoomlaWorks Ltd. & Nuevvo Webware Ltd., released under the GNU/GPL v2 license.
Joomla! is a registered trademark of Open Source Matters, Inc. JoomlaWorks/Nuevvo are not affiliated with or endorsed by Open Source Matters or the Joomla! Project.
designed by Nuevvo