Magento – Magento2 – How to add a new section to customer account page
customer-accountmagento2
I want to add a new section with my own links to the customer account page (see pic) This section should be visible based on my custom extension of the customer entity.
How can I do that?
Best Answer
Create your own extension.
Let's call it StackExchange_Customer.
You will need these files:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Customer My Account (All Pages)" design_abstraction="custom">
<body>
<attribute name="class" value="account"/>
<referenceContainer name="sidebar.main">
<block class="Magento\Framework\View\Element\Html\Links" name="customer_account_navigation_secondary" after="customer_account_navigation" template="Magento_Customer::account/navigation.phtml">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-account-link-secondary"> <!-- duplicate this as many times as you need, just make sure the name is unique -->
<arguments>
<argument name="label" xsi:type="string" translate="true">Some link here</argument>
<argument name="path" xsi:type="string">module/controller/action</argument>
</arguments>
</block>
</block>
</referenceContainer>
</body>
</page>
then run in the console php bin/magento setup:upgrade.
Best Answer
Create your own extension.
Let's call it
StackExchange_Customer
.You will need these files:
app/code/StackExchange/Customer/registration.php
app/code/StackExchange/Customer/etc/module.xml
app/code/StackExchange/Customer/view/frontend/layout/customer_account.xml
then run in the console
php bin/magento setup:upgrade
.