Author Topic: Hide tab when customfield is empty  (Read 283 times)

alexanderflr

  • Beginner
  • *
  • Posts: 38
  • VirtueMart Version: 3.2.2
Hide tab when customfield is empty
« on: September 07, 2017, 12:02:22 pm »
Hi,
I have a custom field in a tab that I would like to hide  when custom field is empty. Any ideas?
My actual code for tabs is:

Code: [Select]
<div id="tab-block" class="tab-block">
<ul class="nav nav-pills" id="ShopTab">
<?php if (!empty($this->product->product_desc)) {?>
<li class="tab_des active">
<a data-toggle="tab" href="#Shop-description"><?php echo JText::_('Shop_JSHOP_FULL_DESCRIPTION'); ?></a>
</li>
<?php }?>
<li class="tab_des">
<a data-toggle="tab" href="#Shop-ingredients"><?php echo JText::_('INGREDIENTS'); ?></a>
</li>

            <li class="tab_des">
<a data-toggle="tab" href="#Shop-allergens"><?php echo JText::_('ALLERGENS'); ?></a>
</li>

<li class="tab_des">
<a data-toggle="tab" href="#Shop-nutrition"><?php echo JText::_('NUTRITIONAL INFORMATION'); ?></a>
</li>      
<li class="tab_review last"><a data-toggle="tab" href="#Shop-reviews"><?php echo JText::_('REVIEWS'); ?></a></li>
</ul>
<div id="ShopTabContent" class="tab-content">
<?php // Product Description
if (!empty($this->product->product_desc)) { ?>

<div id="Shop-description" class="tab-pane fade in product-description active">
<?php /** @todo Test if content plugins modify the product description */ ?>
<span class="title"><?php echo vmText::_(''?></span>
<?php echo $this->product->product_desc?>
</div>
<?php // Product Description END ?>

            <div id="Shop-allergens" class="tab-pane">
<?php echo shopFunctionsF::renderVmSubLayout('customfields', array('product'=>$this->product'position'=>'tabcustom1'));
?>
</div>

            <div id="Shop-ingredients" class="tab-pane">
<?php
echo shopFunctionsF::renderVmSubLayout('customfields', array('product'=>$this->product'position'=>'tabcustom2'));
?>
</div>
<div id="Shop-nutrition" class="tab-pane">

</div>
<div id="Shop-reviews" class="tab-pane fade product-review">
<?php
echo $this->loadTemplate('reviews');
?>

</div>
</div>
</div>
<?php

I'm using Joomla! 3.7.5 Stable, PHP 7.0.18, Virtuemart 3.2.2
Thank you very much!
VM 3.2.4 on Joomla! 3.8.1 Stable, PHP Version 7.0.25

Ghost

  • Jr. Member
  • **
  • Posts: 368
Re: Hide tab when customfield is empty
« Reply #1 on: September 07, 2017, 12:57:22 pm »
Try this:

Code: [Select]
if(!empty($this->product->customfieldsSorted['tabcustom1'])){...

alexanderflr

  • Beginner
  • *
  • Posts: 38
  • VirtueMart Version: 3.2.2
Re: Hide tab when customfield is empty
« Reply #2 on: September 07, 2017, 17:25:04 pm »
Hi,

I tried, and is completely hiding from everywhere even if the field is not empty  :'(
VM 3.2.4 on Joomla! 3.8.1 Stable, PHP Version 7.0.25

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7617
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Hide tab when customfield is empty
« Reply #3 on: September 07, 2017, 18:46:23 pm »
@ghosts code should work

surround each <li>  then each div with the appro. if statement
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

alexanderflr

  • Beginner
  • *
  • Posts: 38
  • VirtueMart Version: 3.2.2
Re: Hide tab when customfield is empty
« Reply #4 on: September 08, 2017, 10:04:32 am »
Hi,

Tried again, and is working now  8). Thank you very much Ghost and GJC Web Design. I appreciate your help.

Have a good weekend!
VM 3.2.4 on Joomla! 3.8.1 Stable, PHP Version 7.0.25