- Posts: 21
COMMUNITY FORUM
Hide empty field
- Leonardo L.
-
Topic Author
- Offline
- Junior Member
Less
More
14 years 3 weeks ago #96133
by Leonardo L.
Hide empty field was created by Leonardo L.
Hello,
I just downloaded your extension to display details about some items.
I used the extrafield option to add personal details that I need, and I would like to know if exist a way to hide the empty field. I mean, if I put some info about a phone, like:
Model: 04052
Weight: 400
Height:
there's a way to hide the "height" that I didn't fill?!
Thanks!
I just downloaded your extension to display details about some items.
I used the extrafield option to add personal details that I need, and I would like to know if exist a way to hide the empty field. I mean, if I put some info about a phone, like:
Model: 04052
Weight: 400
Height:
there's a way to hide the "height" that I didn't fill?!
Thanks!
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
Less
More
- Posts: 3722
14 years 3 weeks ago #96134
by william white
Replied by william white on topic Hide empty field
You might try this in your override
Please Log in or Create an account to join the conversation.
- Leonardo L.
-
Topic Author
- Offline
- Junior Member
Less
More
- Posts: 21
14 years 3 weeks ago #96135
by Leonardo L.
Replied by Leonardo L. on topic Hide empty field
Helllo,
I need to copy this line
if(!empty($extraField->value)) :[/code]
where?!
thanks.
I need to copy this line
if(!empty($extraField->value)) :[/code]
where?!
thanks.
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
Less
More
- Posts: 3722
14 years 3 weeks ago #96136
by william white
Replied by william white on topic Hide empty field
The test should be put in either item.php or category_item.php in the block that is displaying the extra fields, depending on which view you are using.
This should preferably be done inside a K2 override so as not to loose the changes on upgrade
Please see friend request
This should preferably be done inside a K2 override so as not to loose the changes on upgrade
Please see friend request
Please Log in or Create an account to join the conversation.
- Leonardo L.
-
Topic Author
- Offline
- Junior Member
Less
More
- Posts: 21
14 years 3 weeks ago #96137
by Leonardo L.
Replied by Leonardo L. on topic Hide empty field
Hello,
But where do I have to insert the new line? Because I'm not very good in php, I don't want to make a mistake :)
here the code I finded in item.php:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="itemExtraFields"> <h3><?php echo JText::_('Additional Info'); ?></h3> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField):?> <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 endforeach; ?> </ul> <div class="clr"></div> </div>
But where do I have to insert the new line? Because I'm not very good in php, I don't want to make a mistake :)
here the code I finded in item.php:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="itemExtraFields"> <h3><?php echo JText::_('Additional Info'); ?></h3> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField):?> <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 endforeach; ?> </ul> <div class="clr"></div> </div>
Please Log in or Create an account to join the conversation.
- Terry Britton
-
- Offline
- Elite Member
Less
More
- Posts: 198
14 years 3 weeks ago #96138
by Terry Britton
Replied by Terry Britton on topic Hide empty field
Here's a simple solution, although it has some limitations. If you need a more elegant solution see this post.
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php if (!empty($extraField->value)) { ?>[/code] <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 } ?><?php endforeach; ?>
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php if (!empty($extraField->value)) { ?>[/code] <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 } ?><?php endforeach; ?>
Please Log in or Create an account to join the conversation.
- Bjern Potgieter
-
- Offline
- New Member
13 years 8 months ago #96139
by Bjern Potgieter
Replied by Bjern Potgieter on topic Hide empty field
There is also a tutorial here: hide-empty-k2-extra-fields-in-joomla which shows you how to use the joomla override feature with your template so that you don't break your K2 component or get your changes overwritten when you upgrade your K2.
This tutorial hides the empty fields very simply with 2 lines of code.
:)
This tutorial hides the empty fields very simply with 2 lines of code.
:)
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
Less
More
- Posts: 3722
13 years 8 months ago #96140
by william white
Replied by william white on topic Hide empty field
Excellent tutorial!
Please Log in or Create an account to join the conversation.