3

I tried to add new link in the customer account link sidebar with add code below in customer_account.xml with my custom module.

customer_account.xml :

<referenceBlock name="customer_account_navigation">
  <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-owner-reset-employee-password">
     <arguments>
        <argument name="path" xsi:type="string">reset/emppass</argument>
        <argument name="label" xsi:type="string" translate="true">Reset Employee Password</argument>
     </arguments>
  </block>
</referenceBlock>

It's all works and i can see new link there, but how can i add the page for it? So if customer click the link, the customer will send to the custom link page.

  • Is you question just about adding a custom page? In which page is above link is going to be shown? – Purushotam Sangroula Jan 8 '18 at 3:57
  • Yes it is, it will be shown in customer account page, just like "My Orders" link in customer account sidebar, when customer clicked the link customer will send to My Orders page, and my custom page will show like that too. – Edwin Widhiyanto Jan 8 '18 at 4:15
  • You need a routes.xml to create the route to your page and then you need a custom controller. Did you add that link through layout file inside your theme or inside a custom module? – Shawn Abramson Jan 8 '18 at 4:50
  • @ShawnAbramson I add the link inside my custome module – Edwin Widhiyanto Jan 8 '18 at 4:58
2

For this you have to create a module. Inside your module create routes.xml in location app/code/Vendor/Module/etc/frontend/routes.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route frontName="reset" id="reset">
            <module name="Vendor_Module"/>
        </route>
    </router>
</config>

Create layout at location app/code/Vendor/Module/view/frontend/layout/reset_emppass_index.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>
        <referenceContainer name="content">
                 <container name="categories1"  htmlTag="div" htmlClass="categories">
                    <block class="Vendor\Module\Block\YourAnyBlock" name="myblock" template="Vendor_Module::index/index.phtml"/>
                </container>
        </referenceContainer>
    </body>
</page>

Next create a controller index and an action index at app/code/Vendor/Module/Controller/Emppass/Index.php

<?php


namespace Vendor\Module\Controller\Emppass;

class Index extends \Magento\Framework\App\Action\Action
{

    protected $resultPageFactory;

    /**
     * Constructor
     *
     * @param \Magento\Framework\App\Action\Context  $context
     * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
     */
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    /**
     * Execute view action
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        return $this->resultPageFactory->create();
    }
}

Finally create a template at app/code/Vendor/Module/view/frontend/templates/index.phtml

Hello this is my template. I can do anything inside this file.

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.