3

I have added a custom tab to a magento 2 store, however I am unable to set the position. I want it between the reviews tab and the description tab. I am able to add the tab with in the catalog_product_view.xml file, but not able to set order.

I can't seem to find any documentation on how to set order. When I try to add after="" or before="" it does not seem to make a difference.

4 Answers 4

3

This will add your tab before review tab

<referenceBlock name="product.info.details">

<block class="Magento\Catalog\Block\Product\View" name="custom.tab" as="custom" template="product/view/custom.phtml" group="detailed_info"  before ="review.tab">

<arguments>

<argument translate="true" name="title" xsi:type="string">Custom Tab</argument>

</arguments>

</block>

</referenceBlock>
3

Try using this code : -

 <referenceBlock name="product.info.details"> 

<block class="Magento\Review\Block\Product\Review" name="custom.tab" as="custom" template="Magento_Review::review.phtml" group="detailed_info" before="reviews.tab">

<block class="Magento\Review\Block\Form" name="product.review.form" >

      <container name="product.review.form.fields.before" as="form_fields_before" label="Review Form Fields Before"/>

</block>
</block> 
   </referenceBlock>

Yes it should be reviews.tab

Let me know if you still face any issues

2

Thanks for the help.

Using your block above had no difference on order of tabs. I did notice an issue with the name of the reviews block. It should be reviews.tab.

I am able to remove the tab with<referenceBlock name="reviews.tab" remove="true" /> so I know that reviews.tab block name is correct.

I also tried moving the reviews.tab using the following: <move element="reviews.tab" destination="product.info.details" after="custom.tab"/> and that did not work either.

Thanks

4
  • That did not work.
    – JonW
    Commented Apr 11, 2016 at 16:40
  • Here is my block with before reviews tab :
    – JonW
    Commented Apr 11, 2016 at 16:41
  • <referenceBlock name="product.info.details"> <block class="Magento\Catalog\Block\Product\View" name="custom.tab" as="custom" template="product/view/care_info.phtml" group="detailed_info" before="reviews.tab"> <arguments> <argument translate="true" name="title" xsi:type="string">Material Care</argument> </arguments> </block> </referenceBlock>
    – JonW
    Commented Apr 11, 2016 at 16:41
  • Just can't get this into the correct position. I can move the reviews block to another part of product page, but cannot make it display after custom tab inside product.info.details block. Kinda weird.
    – JonW
    Commented Apr 11, 2016 at 16:43
1

At least in Magento 2.4.4 it's going to be

<argument name="sort_order" xsi:type="string">80</argument>

inside your custom tab block, where "80" will define the relative position of a specific tab.

So for example, your complete xml might look like this:

<?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="included_items.tab" as="included_items" template="product/view/included_tab.phtml" group="detailed_info">
<arguments>
<argument translate="true" name="title" xsi:type="string">Included Items</argument>
<argument name="sort_order" xsi:type="string">10</argument>
</arguments>
</block>

<block class="Magento\Catalog\Block\Product\View" name="sizing_chart.tab" as="sizing_chart" template="product/view/sizing_chart_tab.phtml" group="detailed_info">
<arguments>
<argument translate="true" name="title" xsi:type="string">Sizing Chart</argument>
<argument name="sort_order" xsi:type="string">50</argument>
</arguments>
</block>

</referenceBlock>
</body>
</page>

Included Items has index "10" which means it will appear to the left of "Sizing Chart" which has index "50". It's necessary to clean cache after making changes to that xml file.

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.