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">
            <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">
                        <argument translate="true" name="title" xsi:type="string">Product Test</argument>

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?

1 Answer 1


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:

$collectionSize = null; // your code here
if (!$collectionSize) {
<!-- 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 and acknowledge you have read our privacy policy.

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