1

I have created a custom product tab by this tutorial.

<?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="Magento\Catalog\Block\Product\View" name="test.tab" template="Cloudways_Mymodule::custom_tab.phtml" group="detailed_info" >
                <arguments>
                    <argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

I have placed the above code in app/code/Cloudways/Mymodule/view/frontend/layout/catalog_product_view.xml and created a template in app/code/Cloudways/Mymodule/view/frontend/templates which works fine and create one table on product details page.

product details page

What if I have to add more than one tab. How should I write the XML?

I have tried these variations but didn't work:

<?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="Magento\Catalog\Block\Product\View" name="test.tab" template="Cloudways_Mymodule::custom_tab.phtml" group="detailed_info" >
                <arguments>
                    <argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
                </arguments>
            </block>
            <block class="Magento\Catalog\Block\Product\View" name="test_second.tab" template="Cloudways_Mymodule::custom_tab_second.phtml" group="detailed_info" >
                <arguments>
                    <argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

<?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="Magento\Catalog\Block\Product\View" name="test.tab" template="Cloudways_Mymodule::custom_tab.phtml" group="detailed_info" >
                <arguments>
                    <argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
                </arguments>
            </block>
        </referenceBlock>
        <referenceBlock name="product.info.details">
            <block class="Magento\Catalog\Block\Product\View" name="test_second.tab" template="Cloudways_Mymodule::custom_tab_second.phtml" group="detailed_info" >
                <arguments>
                    <argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>
3

The working solution I have for this is:

In your catalog_product_view.xml Layout file:

<referenceBlock name="product.info.details">
        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::catalog/product/tabs/tab1.phtml" name="extra-tab-1" group="detailed_info">
            <arguments>
                <argument name="title" translate="true" xsi:type="string">Extra Tab 1</argument>

            </arguments>
        </block>

        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::catalog/product/tabs/tab2.phtml" name="extra-tab-2" group="detailed_info">
            <arguments>
                <argument name="title" translate="true" xsi:type="string">Extra Tab 2</argument>

            </arguments>
        </block>

</referenceBlock>

Then just create your templates as referenced in the layout and they should appear:

Tab Screenshot

  • Worked!!!!!! :) – Omer Jun 7 '17 at 11:11
  • 1
    :thumbsup: Happy to help – edmondscommerce Jun 7 '17 at 13:19

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.