2

Below my code for xml. I create product tab like below code for product-details page. Vendor\Module\view\frontend\layout\catalog_product_view.xml

<?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <body>
            <referenceBlock name="product.info.details">
                <block class="Vendor\Module\Block\Test" name="test.product" as="deliveryinfo" template="Vendor_Module::product/producttest.phtml" group="detailed_info" ifconfig="vendor_module/general/product_test">
                    <arguments>
                        <argument translate="true" name="title" xsi:type="string">Product Test</argument>
                    </arguments>
                </block>
            </referenceBlock>
        </body>
    </page>

Below Screenshot is product-page. enter image description here Now i try, if collection get Product Test Tab is Enabled and collection get is zero(empty) Product Test Tab is disabled. How it posible using layout xml code?

3

There is no easy way to this using the layout. However, if you need to hide a tab when a collection is empty, you can simply add a check at the beginning of your tab's template (.phtml). Here is the example:

<?php
$collectionSize = null; // your code here
if (!$collectionSize) {
    return;
}
?>
<!-- html here -->

In this example if the size of collection will be 0, then the template won't be drawn and you will see nothing on a product's page:

enter image description here

Alternatively, the tab should be drawn normally:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.