Hello friends. For those who need to add a new link to the sidebar of my account, Magento offers a flexible and simple solution.

By default, this menu is initially declared at
vendor/magento/module-customer/view/frontend/layout/customer_account.xml
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-address-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">Address Book</argument>
<argument name="path" xsi:type="string">customer/address</argument>
<argument name="sortOrder" xsi:type="number">190</argument>
</arguments>
</block>
class=”Magento\Customer\Block\Account\SortLinkInterface” here provided by Magento
name=”customer-account-navigation-address-link”, with the name we can customize according to our purpose
argument name =”label” displays the label for the link
argument name=” path” is the path of the link
argument name=”sortOrder” arranges the order of the links before and after, note that Magento arranges in order of DESC, number of The higher sort order will be at the top.
Now let’s create our customer link.
declare customer_account.xml in module Magepow/YourModule/view/frontend/layout/customer_account.xml
<?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="customer_account_navigation">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-account-new-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">The New Link</argument>
<argument name="path" xsi:type="string">router/demo</argument>
<argument name="sortOrder" xsi:type="number">10</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>

That’s it. You can use the second way, which is to use the declaration in the theme.
app/design/frontend/your_vendor_name/your_theme_name/Magento_Customer/layout/customer_account.xml
<?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="customer_account_navigation">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-account-new-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">The New Link</argument>
<argument name="path" xsi:type="string">router/demo</argument>
<argument name="sortOrder" xsi:type="number">10</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
We hope that this article will be helpful to you.
Thanks for reading!
Leave a Reply