- Posts: 12
COMMUNITY FORUM
Hide individual Extra Field if empty
- Wesley
- Topic Author
- Offline
- New Member
Less
More
12 years 8 months ago #61615
by Wesley
Hide individual Extra Field if empty was created by Wesley
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:This works fine but I'm not able to hide these if empty. What if statement would I use?
Thank you!
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; ?>
<?php if(What Would Go Here) ?>
<?php $custom = $this->item->extra_fields; echo $custom[2]->value; ?>
<?php endif; ?>
Thank you!
Please Log in or Create an account to join the conversation.
- william white
- Offline
- Platinum Member
Less
More
- Posts: 3722
12 years 8 months ago #61616
by william white
Replied by william white on topic Re: Hide individual Extra Field if empty
something like
if(!empty($str))
might just do the trick
if(!empty($str))
might just do the trick
Please Log in or Create an account to join the conversation.
- Wesley
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
12 years 8 months ago - 12 years 8 months ago #61617
by Wesley
Replied by Wesley on topic Re: Hide individual Extra Field if empty
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:
Thanks again!
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!
Please Log in or Create an account to join the conversation.
- william white
- Offline
- Platinum Member
Less
More
- Posts: 3722
12 years 8 months ago #61618
by william white
Replied by william white on topic Re: Hide individual Extra Field if empty
try changin $str to $custom[2]->value
the code i send was for an illustration
Play around with it a bit, i havent tested
the code i send was for an illustration
Play around with it a bit, i havent tested
Please Log in or Create an account to join the conversation.
- Julie
- Offline
- New Member
Less
More
- Posts: 2
12 years 7 months ago #61619
by Julie
Replied by Julie on topic Re: Hide individual Extra Field if empty
Wesley, were you able to figure this one out? I need to do this too.
Please Log in or Create an account to join the conversation.
- Josh
- Offline
- Senior Member
Less
More
- Posts: 63
12 years 7 months ago - 12 years 7 months ago #61620
by Josh
Replied by Josh on topic Re: Hide individual Extra Field if empty
To display extra fields individually and in different places on the page I used this post..
getk2.org/documentation/tips-a-tricks/item/221-custom-admin-templates-and-calling-specific-extra-field-data
The to hide them again I use..
<?php if($extrafields != "") { ?>
<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.
getk2.org/documentation/tips-a-tricks/item/221-custom-admin-templates-and-calling-specific-extra-field-data
The to hide them again I use..
<?php if($extrafields != "") { ?>
<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.
Please Log in or Create an account to join the conversation.
- CHAR
- Offline
- New Member
Less
More
- Posts: 2
12 years 3 months ago #61621
by CHAR
Replied by CHAR on topic Re: Hide individual Extra Field if empty
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>
<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>
Please Log in or Create an account to join the conversation.
- Yanick
- Offline
- New Member
Less
More
- Posts: 9
12 years 2 months ago #61622
by Yanick
Replied by Yanick on topic Re: Hide individual Extra Field if empty
This bugged the hell out of me. I've posted a solution here:
getk2.org/community/New-to-K2-Ask-here-first/158831-extrafields-do-not-alternate-css-class-solved
getk2.org/community/New-to-K2-Ask-here-first/158831-extrafields-do-not-alternate-css-class-solved
Please Log in or Create an account to join the conversation.