1

I want to display the Login and Register link in one of my custom module. I have got a solution for displaying the Login link by giving the below code in block file:

public function checkCustomerLogin()
    {
        $customer_data = [];
        if (!$this->_customerSession->isLoggedIn()) {
            $customer_data['text'] = "Login";
            $customer_data['url'] = $this->_storeManager->getStore()->getUrl('customer/account/login');
        } else {
            $customer_data['text'] = "Logout";
            $customer_data['url'] = $this->_storeManager->getStore()->getUrl('customer/account/logout');
        }
        return $customer_data;
    }

But I haven't got a solution for displaying the register link.

Could anyone please help me to resolve this issue?

3
  • Hello @Siva, Have you tried $this->_storeManager->getStore()->getUrl('customer/account/create'); to get registration link Dec 10, 2019 at 10:11
  • @AshishRanade, Where I have to add this code?
    – MagentoDev
    Dec 10, 2019 at 10:21
  • in side your template file you can use $this->getUrl('customer/account/create'); will help you to get the registration link Dec 10, 2019 at 10:54

1 Answer 1

1

You can get Register link with help of layout xml. create your defualt.xml or your custom.xml and put below code

<referenceBlock name="header.links">
    <block class="Magento\Customer\Block\Account\RegisterLink" name="register-link-ajax"  after="-">
        <arguments>
            <argument name="label" xsi:type="string" translate="true">Register</argument>
                  <argument name="class" xsi:type="string">registerlink</argument>
            </arguments>
    </block>
</referenceBlock>
2
  • We have the register link in desktop view but we wanted it to display in mega menu which we have created by our own module. I have tried in putting the code in default.xml of that module but it displays in desktop view and not in mobile view and also now we have two of the register links.
    – MagentoDev
    Dec 10, 2019 at 13:20
  • <referenceBlock name="header.links"> <action method="unsetChild" ifconfig='mobilelogin/moduleoption/enable'> <argument name="alias" xsi:type="string">register-link</argument> </action> </referenceBlock> Using above code you can remove defualt link.so after applying this code you will have only one link and that is new one. for mega menu you need to do same code in mega menu related xml files. Dec 10, 2019 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.