2

I use the below code in a module within catalog_product_view.xml to display a new Tab on the Product Page.

<body>
    <referenceBlock name="product.info.details">
        <block class="Magento\Catalog\Block\Product\View" name="example.tab" template="Vendor_Module::example.phtml" group="detailed_info">
            <arguments>
                <argument translate="true" name="title" xsi:type="string">Example Title</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

I'd like to know if you can Display/Hide this based on a Product Attribute? Normally, I'd embed an IF within the phtml file. But wondered if it could also be done this way instead?

Reason why I ask, is because I don't want the Tab to load if a Product Attribute = Yes. As the information might not be relevant.

4
  • You can do that Block level and system config changes support at if condition at layout
    – Amit Bera
    Sep 20, 2018 at 13:14
  • Can you reference some examples?
    – Craig
    Sep 20, 2018 at 13:16
  • for layout magento.stackexchange.com/a/99841/4564
    – Amit Bera
    Sep 20, 2018 at 13:18
  • ifconfig is only used to check for an admin config is 0 or 1 . Sep 20, 2018 at 13:29

1 Answer 1

0

You can do that even though its not recommended in my opinion .

plus what you have done already , you can create an after plugin for the public method Magento\Catalog\Block\Product\View\Tabs::getTabs() which will return an array of the tabs that will be added to the page .

Then you can use the registry to get the current product object and check for the attribute you want , if yes then you can just remove that tab (title in your case) from the returned array in getTabs() ,or else return it as it is .

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.