2

I created two Tabs in customer account Navigation, 1st tab is working 2nd tab is not working

customer_account.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-index">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/index</argument>
                    <argument name="label" xsi:type="string" translate="true"> Tab Name</argument>
                </arguments>
            </block>
        </referenceBlock>
        <referenceBlock name="customer_account_navigation">
        <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-history">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/history</argument>
                    <argument name="label" xsi:type="string" translate="true"> Tab Name 1</argument>
                </arguments>
        </block>
    </referenceBlock>
    </body>
 </page> 

layout.xml

<referenceBlock name="customer_account_navigation">
            <referenceContainer name="content">
                <block class="Package\Module\Block\Index\Index" name="module_index_index" template="Module_Namespace::module_index_index.phtml"></block>
            </referenceContainer>
        </referenceBlock>
        <referenceBlock name="customer_account_navigation">
             <referenceContainer name="content">
                <block class="Package\Module\Block\Index\History" name="module_index_history" template="Module_Namespace::module_index_history.phtml"></block>
            </referenceContainer>
        </referenceBlock>
6
+50

First in customer_account.xml instead of two <referenceBlock name="customer_account_navigation"> you have to merge them like below

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-index">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/index</argument>
                    <argument name="label" xsi:type="string" translate="true"> Tab Name</argument>
                </arguments>
            </block>
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-history">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/history</argument>
                    <argument name="label" xsi:type="string" translate="true"> Tab Name 1</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
 </page> 

Then instead of a single layout.xml you have to create two separate layout files to call your templates

  1. module_index_index.xml
  2. module_index_history.xml

With below code

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/> 
    <body>           
        <referenceContainer name="content">
            <block class="Package\Module\Block\Index\Index" name="module_index_index" template="Module_Namespace::module_index_index.phtml"></block> 
        </referenceContainer> 
    </body> 
</page>  

For second layout file change your block name and template path

2

Now try this

customer_account.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-index">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/index</argument>
                    <argument name="label" xsi:type="string" translate="true">Tab Name</argument>
                </arguments>
            </block>
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-history">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/history</argument>
                    <argument name="label" xsi:type="string" translate="true">Tab Name 1</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
 </page> 

module_index_history.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
    <body>
         <referenceContainer name="content">
            <block class="Package\Module\Block\Index\History" name="module_index_history" template="Module_Namespace::module_index_history.phtml"></block>
        </referenceContainer>
    </body>
</page>
  • Same output only both page content show only one page 2nd page empty – Magento 2 Dec 7 '17 at 5:00
  • 2nd page phtml file add your code and call it. – Ravindrasinh Zala Dec 7 '17 at 5:10
  • Where i need to add – Magento 2 Dec 7 '17 at 5:11
  • please check my updated code – Ravindrasinh Zala Dec 7 '17 at 5:25
0

Replace your code in file customer_account.xml from

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-index">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/index</argument>
                    <argument name="label" xsi:type="string" translate="true"> Tab Name</argument>
                </arguments>
            </block>
        </referenceBlock>
        <referenceBlock name="customer_account_navigation">
        <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-history">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/history</argument>
                    <argument name="label" xsi:type="string" translate="true"> Tab Name 1</argument>
                </arguments>
        </block>
    </referenceBlock>
    </body>
 </page>

To:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-index">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/index</argument>
                    <argument name="label" xsi:type="string" translate="true"> Tab Name1</argument>
                </arguments>
            </block>
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-module-index-history">
                <arguments>
                    <argument name="path" xsi:type="string">module/index/history</argument>
                    <argument name="label" xsi:type="string" translate="true"> Tab Name2</argument>
                </arguments>
            </block>
         </referenceBlock>
    </body>
 </page>
  • After add this code tab itself not showing – Magento 2 Dec 7 '17 at 5:00
  • Updated ans pls check. Have you run: bin/magento setup:di:compile? – Abdul Dec 7 '17 at 5:12
  • Tab itself not showing – Magento 2 Dec 7 '17 at 5:16

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.