Domanda

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.

È stato utile?

Soluzione

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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top