4

I am creating custom customer navigation tab using my module.

<?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>
    <referenceBlock name="customer_account_navigation">
        <block class="Magento\Framework\View\Element\Html\Link\Current"  name="customer-account-navigation-custom-link">
            <arguments>
                <argument name="path" xsi:type="string">link/index</argument>
                <argument name="label" xsi:type="string">Custom link</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>
</page>

When i click on my custom tab its page title is Billing Agreements how to set page title in my custom tab

0
10

For set Page title of current link in customer account navigation page, You have set Title inside controller file. In Your case, Controller file link/index, so index.php file is your controller file.

Go to controller file,

namespace path/To/Your/File;

use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;

class Index extends \Magento\Framework\App\Action\Action
{
    /**
     * @var PageFactory
     */
    protected $resultPageFactory;

    public function __construct(
        Context $context,
        PageFactory $resultPageFactory
    ) {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    /**
     * Default customer account page
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->set(__('Billing Agreements'));
        return $resultPage;
    }
}
3
  • My custom tab is show before Dashboard link i want to add my tab at the end how can i do this – ND17 Dec 22 '15 at 10:19
  • you can add attribute before or after inside customer_account.xml file with <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-custom-link" after="customer-account-navigation-billing-agreements-link"> – Rakesh Jesadiya Dec 22 '15 at 11:08
  • How to redirect customer login page when customer is not login & run url in broswer? – MagikVishal Jan 28 '16 at 10:50
7

Your link_index layout file should be

<?xml version="1.0"?>
<page layout="2columns-left" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">   
    <update handle="customer_account"/>
    <head>
        <title>YOUR PAGE CUSTOM TITLE</title>
    </head>
    <body>
        <referenceBlock name="page.main.title">
            <action method="setPageTitle">
                <argument translate="true" name="title" xsi:type="string">YOUR CONTENT TITLE</argument>
            </action>
        </referenceBlock>
        <referenceContainer name="content">
            <block class="YOUR_NAMESPACE\YOUR_EXTENSION\Block\Customer\YOURBLOCK" name="test" template="customer/test.phtml"/>
        </referenceContainer>
    </body>
</page>
2
  • My custom tab is show before Dashboard link i want to add my tab at the end how can i do this – ND17 Dec 22 '15 at 9:57
  • How can we translate given title in <head> tag in this xml? – Kaushal Suthar Jun 7 '17 at 9:33
2

You can set after or before with block tag and manage your link in navigation tab.Below is updated xml file check and verify.

<?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>
    <referenceBlock name="customer_account_navigation">
        <block class="Magento\Framework\View\Element\Html\Link\Current"  name="customer-account-navigation-custom-link" after="-">
            <arguments>
                <argument name="path" xsi:type="string">link/index</argument>
                <argument name="label" xsi:type="string">Custom link</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>
</page>

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.