0

I'm trying to add a custom tab on Customer Account Frontend.

I've successfully added the link but when clicking it all I get is a blank page.

There is no clue in the logs.

This is what I have

customer_account.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>
            <!-- Add custom links -->
            <referenceBlock name="customer_account_navigation">
                <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-subscriptions-link">
                    <arguments>
                        <argument name="label" xsi:type="string" translate="true">Tab Name</argument>
                        <argument name="path" xsi:type="string">frontName/controller</argument>
                    </arguments>
                </block>
            </referenceBlock>
   </body>
</page>

frontname_controller_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
    <body>
        <referenceContainer name="content"  cacheable="false">
            <block class="Company\Module\Block\BlockClass"
                   name="name"
                   template="Company_module::templateName.phtml"
            />
        </referenceContainer>
    </body>
</page>

Controller

class Index extends Action
{
    /**
     * @var PageFactory
     */
    protected $resultPageFactory;

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

    /**
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
        /** @var \Magento\Framework\View\Result\Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->set(__('My Title'));
        return $resultPage;
    }
}

Block

class BlockClass extends Template
{
    /**
     * Subscriptions constructor.
     * @param Context $context
     */
    public function __construct(Context $context)
    {
        parent::__construct($context);
    }
}

Template:

<h1>It Works!</h1>

I should point out that the right controller is called. Given that the right title is set to the page. Yet no html is displayed.

What am I missing. Any pointers are highly appreciated.

1 Answer 1

0

I found out what the problem was.

In frontname_controller_index.xml

Setting the layout attribute of the page node as follows

layout="admin-2columns-left"

was causing the undesired behaviour. How did I end up with this, I'm not really sure. I blame it on copy-pasting in a hurry.

Basically all I had to was remove the layout attribute on the page node. Changing it to "2columns-left" works as well.

Your Answer

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

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