4

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?

enter image description here

8

Create your own extension.
Let's call it StackExchange_Customer.
You will need these files:

app/code/StackExchange/Customer/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'StackExchange_Customer',
    __DIR__
);

app/code/StackExchange/Customer/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="StackExchange_Customer" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Customer"/>
        </sequence>
    </module>
</config>

app/code/StackExchange/Customer/view/frontend/layout/customer_account.xml

<?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.

7
  • you didn't explain the controller part 'module/controller/action' what should it be? 'customer/account/custom' ? What class should that controller extend if so? etc
    – OZZIE
    May 23 '18 at 9:45
  • because there was no requirement for the controller action. I just explained how to add a link. I assumed the OP knows how to create a controller
    – Marius
    May 23 '18 at 10:41
  • Hi @Marius how to include all links under one link, means toggle dropdown in magento2 Dec 5 '18 at 7:34
  • @Marius Hey ! I use your answer but there is no effect . no any tab show in customer account section
    – HaFiz Umer
    Jun 21 '19 at 12:24
  • 1
    @Marius your answer perfect . it was my mistake i solved . But Css not applied . It show simple side bar . How can give same look as magento defauld side have look . please update your answer how can add bootstrap or custom css class add and use in customer_account.xml . Thank you
    – HaFiz Umer
    Jun 23 '19 at 20:18

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.