3

I am rebuilding an old 1.x module for Magento 2, adding a "customer invoices" page to the Customer Account section of the site, which brings in PDF invoices from a proprietary external source.

I have accomplished:

  • respond to the request at /my_invoices/invoices/index with an action controller and serve the appropriate view, template, etc
  • add a link to that page in the customer_account_navigation links block

With these I can "make it work" but I would like to tie the UI together to make it look like the customer is still in the Customer Account section.

What I need to do is bring that customer_account_navigation menu to my custom page at /my_invoices/invoices/index.

In the app/code/MyNamespace/CustomerInvoices/view/frontend/layout/my_invoices_invoices_index.xml file I attempted to reference the sidebar.main container and add a customer_account_navigation block:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">        
    <referenceBlock name="content">
        <block
            template="invoices/index/content.phtml"
            class="MyNamespace\CustomerInvoices\Block\Invoices"
            name="my_customerinvoices"/>
    </referenceBlock>

    <body>
        <referenceContainer name="sidebar.main">
            <block class="Magento\Framework\View\Element\Html\Links" name="customer_account_navigation" before="-" template="Magento_Customer::account/navigation.phtml">
                <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-invoices-link">
                    <arguments>
                        <argument name="label" xsi:type="string" translate="true">Invoices</argument>
                        <argument name="path" xsi:type="string">my_invoices/invoices</argument>
                    </arguments>
                </block>
            </block>
        </referenceContainer>
    </body>
</page>

But this results in only the explicitly defined link to my invoices page appears in the menu. I would like to have all of the links that normally appear on the sidebar menu in the customer account area to also appear here.

Is there a way to tell the XML to simply inherit the links from all the other modules that populate that menu?

3 Answers 3

5

Self-answer, thanks for being my rubber duckie:

In the my_invoices_invoices_index.xml file, inside the node, I added the following:

<update handle="customer_account"/>

and it includes the sidebar menu from the customer_account layout.

1
  • Is not working for me without the line : layout="2columns-left"
    – Nico2P
    May 10 at 7:51
3

set the layout at your xml file to layout="2columns-left" and you'll get the customer account page sidebar

this will work enter image description here

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
2

Are you looking for something like this,

<?xml version="1.0"?>
<!--
/**
 * Copyright © 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">
    <update handle="customer_account"/>
    <head>
        <title>Custom Jewelery Page</title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Custom\Module\Block\Custom\Customer" name="custom_customer" template="customer/customdesign.phtml" />
            <block class="Magento\Customer\Block\Account\Dashboard" name="customer.account.link.back" template="Magento_Customer::account/link/back.phtml" cacheable="false"/>
        </referenceContainer>
    </body>
</page>

This can be used to create new layout same as customer account page with our custom phtml rendering data.

OR

If you are looking to add new link in sidebar menu, below can be helpful to you.

<?xml version="1.0"?>
<!--
/**
 * Copyright © 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-customjewelery-link">
                <arguments>
                    <argument name="path" xsi:type="string">custom/controller/action</argument>
                    <argument name="label" xsi:type="string">My Custom Requests</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

This will add a link at the bottom of side bar menu customer account pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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