Hide Description tab if there is no text?
Posted: Sat Dec 01, 2012 6:37 am
Is it possible to hide that tab if there has been no description input?
Thanks very much.
Thanks very much.
OpenCart Community Forum - Discuss shopping cart and e-commerce solutions.
https://forum.opencart.com/
Yes it is possible, you just need to make some changes in "catalog/view/theme/default/template/product/product.tpl" assuming you are using the default template or "catalog/view/theme/default/'template name'/product/product.tpl" if using a different templatefrosty1_4me wrote:Is it possible to hide that tab if there has been no description input?
Thanks very much.
Code: Select all
<a href="#tab-description"><?php echo $tab_description; ?></a>
Code: Select all
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
Code: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?>
<a href="#tab-description"><?php echo $tab_description; ?></a>
<?php } ?>
Code: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?>
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
<?php } ?>
rebdog wrote: ↑Sat Dec 01, 2012 2:31 pmYes it is possible, you just need to make some changes in "catalog/view/theme/default/template/product/product.tpl" assuming you are using the default template or "catalog/view/theme/default/'template name'/product/product.tpl" if using a different templatefrosty1_4me wrote:Is it possible to hide that tab if there has been no description input?
Thanks very much.
You need to test if $description is empty so you need to wrap
andCode: Select all
<a href="#tab-description"><?php echo $tab_description; ?></a>
in a check to see if $description is empty, as belowCode: Select all
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
andCode: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?> <a href="#tab-description"><?php echo $tab_description; ?></a> <?php } ?>
There is a vqmod attached that might help, if you are using the default templateCode: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?> <div id="tab-description" class="tab-content"><?php echo $description; ?></div> <?php } ?>
Cheers
rebdog wrote: ↑Sat Dec 01, 2012 2:31 pmYes it is possible, you just need to make some changes in "catalog/view/theme/default/template/product/product.tpl" assuming you are using the default template or "catalog/view/theme/default/'template name'/product/product.tpl" if using a different templatefrosty1_4me wrote:Is it possible to hide that tab if there has been no description input?
Thanks very much.
You need to test if $description is empty so you need to wrap
andCode: Select all
<a href="#tab-description"><?php echo $tab_description; ?></a>
in a check to see if $description is empty, as belowCode: Select all
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
andCode: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?> <a href="#tab-description"><?php echo $tab_description; ?></a> <?php } ?>
There is a vqmod attached that might help, if you are using the default templateCode: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?> <div id="tab-description" class="tab-content"><?php echo $description; ?></div> <?php } ?>
Cheers
In file /catalog/view/theme/journal2/template/product/product.tpl
Code: Select all
<?php if (!$this->journal2->settings->get('hide_product_description')) { ?>
<li <?php if ($is_active) { echo 'class="active"'; $is_active = false; } ;?>><a href="#tab-description" data-toggle="tab"><?php echo $tab_description; ?></a></li>
<?php } ?>
Code: Select all
<ul class="nav nav-tabs" role="tablist">
<?php $i = 0; foreach($tabs as $tab) { $i++;
$id = 'tab_'.$i;
if($tab['content'] == 'description') { $id = 'tab-description'; }
if($tab['content'] == 'attribute') { $id = 'tab-attribute'; }
if($tab['content'] == 'review') { $id = 'tab-review'; }
$class = false;
if($i == 1) { $class = 'class="active"'; $new_active = $id; }
echo '<li role="presentation" ' . $class . '><a href="#'.$id.'" aria-controls="'.$id.'" role="tab" data-toggle="tab">'.$tab['heading'].'</a></li>';
} ?>
</ul>
<div class="tab-content">
<?php $i = 0; foreach($tabs as $tab) { $i++;
$id = 'tab_'.$i;
if($tab['content'] != 'description' && $tab['content'] != 'attribute' && $tab['content'] != 'review') {
echo '<div id="'.$id.'" class="tab-pane';
if($new_active == $id) { echo ' active'; }
echo '" role="tabpanel">'.$tab['content'].'</div>';
}
} ?>
Code: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?>
Code: Select all
<?php } ?>
Please help me fix the modifier from opencart 2.0 under 3.0 where twigs are already used. I need to hide the description tab if it is empty. Php conditions in twigs do not work. The template is standard, the modifier is attached. Thanks a lot!rebdog wrote: ↑Sat Dec 01, 2012 2:31 pmYes it is possible, you just need to make some changes in "catalog/view/theme/default/template/product/product.tpl" assuming you are using the default template or "catalog/view/theme/default/'template name'/product/product.tpl" if using a different templatefrosty1_4me wrote:Is it possible to hide that tab if there has been no description input?
Thanks very much.
You need to test if $description is empty so you need to wrap
andCode: Select all
<a href="#tab-description"><?php echo $tab_description; ?></a>
in a check to see if $description is empty, as belowCode: Select all
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
andCode: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?> <a href="#tab-description"><?php echo $tab_description; ?></a> <?php } ?>
There is a vqmod attached that might help, if you are using the default templateCode: Select all
<?php if (!(ctype_space($description) || $description == '')) { ?> <div id="tab-description" class="tab-content"><?php echo $description; ?></div> <?php } ?>
Cheers
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Скрыть вкладку с описанием без текста</name>
<code>hide_description_tab_without_text</code>
<version></version>
<author></author>
<link></link>
<file path="catalog/view/theme/default/template/product/product.twig">
<operation>
<search>
<![CDATA[<li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>]]>
</search>
<add position="replace">
<![CDATA[<?php if ($description) { ?><li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li><?php } ?>]]>
</add>
</operation>
<operation>
<search>
<![CDATA[<div class="tab-pane active" id="tab-description">{{ description }}</div>]]>
</search>
<add position="replace">
<![CDATA[<?php if ($description) { ?><div class="tab-pane active" id="tab-description">{{ description }}</div><?php } ?>]]>
</add>
</operation>
</file>
</modification>
NadezhdaSmirnova wrote: ↑Thu Dec 09, 2021 7:04 amCode: Select all
<?xml version="1.0" encoding="utf-8"?> <modification> <name>Скрыть вкладку с описанием без текста</name> <code>hide_description_tab_without_text</code> <version></version> <author></author> <link></link> <file path="catalog/view/theme/default/template/product/product.twig"> <operation> <search> <![CDATA[<li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>]]> </search> <add position="replace"> <![CDATA[{% if description %} <li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>{% endif %}]]> </add> </operation> <operation> <search> <![CDATA[<div class="tab-pane active" id="tab-description">{{ description }}</div>]]> </search> <add position="replace"> <![CDATA[{% if description %}<div class="tab-pane active" id="tab-description">{{ description }}</div>{% endif %}]]> </add> </operation> </file> </modification>
Thank you very much. Can you tell me how to activate the tab with attributes?xxvirusxx wrote: ↑Thu Dec 09, 2021 4:06 pmNadezhdaSmirnova wrote: ↑Thu Dec 09, 2021 7:04 amCode: Select all
<?xml version="1.0" encoding="utf-8"?> <modification> <name>Скрыть вкладку с описанием без текста</name> <code>hide_description_tab_without_text</code> <version></version> <author></author> <link></link> <file path="catalog/view/theme/default/template/product/product.twig"> <operation> <search> <![CDATA[<li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>]]> </search> <add position="replace"> <![CDATA[{% if description %} <li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>{% endif %}]]> </add> </operation> <operation> <search> <![CDATA[<div class="tab-pane active" id="tab-description">{{ description }}</div>]]> </search> <add position="replace"> <![CDATA[{% if description %}<div class="tab-pane active" id="tab-description">{{ description }}</div>{% endif %}]]> </add> </operation> </file> </modification>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Скрыть вкладку с описанием без текста</name>
<code>hide_description_tab_without_text</code>
<version></version>
<author></author>
<link></link>
<file path="catalog/view/theme/default/template/product/product.twig">
<operation>
<search>
<![CDATA[<li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>]]>
</search>
<add position="replace">
<![CDATA[{% if description %} <li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>{% endif %}]]>
</add>
</operation>
<operation>
<search>
<![CDATA[<div class="tab-pane active" id="tab-description">{{ description }}</div>]]>
</search>
<add position="replace">
<![CDATA[{% if description %}<div class="tab-pane active" id="tab-description">{{ description }}</div>{% endif %}]]>
</add>
</operation>
<operation>
<search>
<![CDATA[<li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]>
</search>
<add position="replace">
<![CDATA[<li class="active"><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]>
</add>
</operation>
</file>
</modification>
Code: Select all
<operation>
<search>
<![CDATA[<li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]>
</search>
<add position="replace">
<![CDATA[<li class="active"><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]>
</add>
</operation>
It does not display characteristics like this, the tab is active, but does not show characteristics. I tried to add more like this:xxvirusxx wrote: ↑Thu Dec 09, 2021 10:56 pmThen delete this codeCode: Select all
<operation> <search> <![CDATA[<li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]> </search> <add position="replace"> <![CDATA[<li class="active"><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]> </add> </operation>
Code: Select all
<operation>
<search>
<![CDATA[<div class="tab-pane active" id="tab-description">{{ description }}</div>]]>
</search>
<add position="replace">
<![CDATA[<div class="tab-pane id="tab-description">{{ description }}</div>]]>
</add>
</operation>
<operation>
<search>
<![CDATA[<div class="tab-pane" id="tab-specification">]]>
</search>
<add position="replace">
<![CDATA[<div class="tab-pane" active id="tab-specification">]]>
</add>
</operation>
OpenCart itself IS easy to handle.
Because class active is already set for Description....NadezhdaSmirnova wrote: ↑Thu Dec 09, 2021 11:46 pmAll the same does not display, you need to click on the adjacent tab and switch back. Why is it not always easy with an opencart?
Code: Select all
<operation>
<search>
<![CDATA[<li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]>
</search>
<add position="replace">
<![CDATA[
{% if description %}
<li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>
{% else %}
<li class="active"><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>
{% endif %}
]]>
</add>
</operation>
Thank you sincerely. I slightly tweaked the code, below is a ready-made working solution. If the description is not filled in, the tab with characteristics is activated, in the same way you can hide the characteristics if they are not filled in, and activate the tab with reviews.xxvirusxx wrote: ↑Fri Dec 10, 2021 12:52 amBecause class active is already set for Description....NadezhdaSmirnova wrote: ↑Thu Dec 09, 2021 11:46 pmAll the same does not display, you need to click on the adjacent tab and switch back. Why is it not always easy with an opencart?
And you need to make an extra change to set class active for Attributes when Description is empty.
Code: Select all
<operation> <search> <![CDATA[<li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]> </search> <add position="replace"> <![CDATA[ {% if description %} <li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li> {% else %} <li class="active"><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li> {% endif %} ]]> </add> </operation>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Скрыть вкладку с описанием без текста</name>
<code>hide_description_tab_without_text</code>
<version></version>
<author></author>
<link></link>
<file path="catalog/view/theme/default/template/product/product.twig">
<operation>
<search>
<![CDATA[<li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>]]>
</search>
<add position="replace">
<![CDATA[{% if description %}<li class="active"><a href="#tab-description" data-toggle="tab">{{ tab_description }}</a></li>{% endif %}]]>
</add>
</operation>
<operation>
<search>
<![CDATA[<div class="tab-pane active" id="tab-description">{{ description }}</div>]]>
</search>
<add position="replace">
<![CDATA[{% if description %}<div class="tab-pane active" id="tab-description">{{ description }}</div>{% endif %}]]>
</add>
</operation>
<operation>
<search>
<![CDATA[<li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>]]>
</search>
<add position="replace">
<![CDATA[
{% if description %}
<li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>
{% else %}
<li class="active"><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>
{% endif %}
]]>
</add>
</operation>
<operation>
<search>
<![CDATA[<div class="tab-pane" id="tab-specification">]]>
</search>
<add position="replace">
<![CDATA[
{% if description %}
<div class="tab-pane" id="tab-specification">
{% else %}
<div class="tab-pane active" id="tab-specification">
{% endif %}
]]>
</add>
</operation>
</file>
</modification>