VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: alexanderflr on September 07, 2017, 12:02:22 PM

Title: Hide tab when customfield is empty
Post by: alexanderflr 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:


<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!
Title: Re: Hide tab when customfield is empty
Post by: Ghost on September 07, 2017, 12:57:22 PM
Try this:

if(!empty($this->product->customfieldsSorted['tabcustom1'])){...
Title: Re: Hide tab when customfield is empty
Post by: alexanderflr on September 07, 2017, 17:25:04 PM
Hi,

I tried, and is completely hiding from everywhere even if the field is not empty  :'(
Title: Re: Hide tab when customfield is empty
Post by: GJC Web Design on September 07, 2017, 18:46:23 PM
@ghosts code should work

surround each <li>  then each div with the appro. if statement
Title: Re: Hide tab when customfield is empty
Post by: alexanderflr 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!