I am trying to add refer a friend
link in the customer account page.
I followed these links.
It doesnt work for me
customer_account.xml
<referenceBlock name="customer_account_navigation">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="refer-a-friend">
<arguments>
<argument name="path" xsi:type="string">customer/refer</argument>
<argument name="label" xsi:type="string">Refer a Friend</argument>
</arguments>
</block>
</referenceBlock>
routes.xml
in app/code/YX/Customer/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="yx_customer" id="yx_customer">
<module name="YX_Customer"/>
</route>
</router>
</config>
customer_refer_index.xml
in app/code/Vendor/Module/view/frontend/layout/customer_refer_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">
<update handle="customer_account"/>
<body>
<referenceContainer name="content">
<block class="YX\Customer\Block\Friend"
name="referFriend"
template="Magento_Customer::account/refer_a_friend.phtml"
/>
</referenceContainer>
</body>
Block file in app/code/YX/Customer/Block/Friend
class Friend extends Template
{
public function __construct(Context $context)
{
parent::__construct($context);
}
}
Controller app/code/YX/Customer/Controller/Refer/Index.php
class Index extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
return $this->resultPageFactory->create();
}
}
refer-a-friend.phtml
<div > Hello this is my template. I can do anything inside this file.</div>
I have no idea what I am doing wrong.