Question

I am trying to create a custom tab in Customer my account area and adding a link in the left bar to it, have followed the code structure similar to this article:

https://www.mageplaza.com/devdocs/add-custom-tab-customer-account-magento-2.html

It shows the link in the left sidebar and when I check profiler, the code shows that my controller executed, but somehow it's not reaching my template phtml file which is already located at its defined directory under the given path in this XML. (bulkAdd is the route name defined in routes.xml)

Below are the codes:

  1. 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>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Customer\Block\Account\Delimiter" name="customer.account.navigation.plus91.bulk.delimiter.top"
                   template="Magento_Customer::account/navigation-delimiter.phtml">
            </block>
            <block class="Magento\Framework\View\Element\Html\Link\Current"
                   name="customer.account.navigation.bulk.index.index">
                <arguments>
                    <argument name="path" xsi:type="string">bulkAdd/customer</argument>
                    <argument name="label" xsi:type="string" translate="true">Bulk Order</argument>
                </arguments>
            </block>
            <!--<block class="Magento\Framework\View\Element\Template" name="bulk-link"
            template="Plus91_Bulk::account/navigation.phtml" before="-"/> -->
        </referenceBlock>
    </body>
</page>
  1. bulkAdd_customer_index.xml
<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <head>
          <css src="css/bulkadd.css" />
          <script src="js/bulkadd.js"/>
     </head> 
     <!--<update handle="customer_account"/> -->
    <body>
        <referenceBlock name="page.main.title"> 
        <action method="setPageTitle"> 
            <argument translate="true" name="title" xsi:type="string">Bulk Inquiry</argument> 
        </action> 
        </referenceBlock> 
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="bulkAdd_bulkorder_index" template="Plus91_Bulk::bulkorder/index.phtml" />
        </referenceContainer>
    </body>
</page>
  1. Controller/Customer/Index.php
<?php 
namespace Plus91\Bulk\Controller\Customer; 
class Index extends \Magento\Framework\App\Action\Action { 
 public function execute() { 
  
     $this->_view->loadLayout(); 
      $this->_view->renderLayout(); 
 } 
  
} 
?>
  1. And the phtml file just contains simple html without any php code.

There is no error in the error log file, profiler shows the controller is being executed and shows the output if I put something there.

Already ran setup:upgrade and cleared cache many times, nothing worked for me.

Any quick help would be appreciated.

Can see navigation link fine

Page appears like this

No correct solution

OTHER TIPS

Please Paste this code in your custom module:-

/view/frontend/layout/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>
            <move element="customer-account-navigation-privacy-policy"  destination="customer_account_navigation" after="customer-account-navigation-wish-list-link"/>
            <referenceBlock name="customer_account_navigation">
                <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-privacy-policy">
                    <arguments>
                        <argument name="label" xsi:type="string" translate="true">Privacy Policy</argument>
                        <argument name="path" xsi:type="string">gdpr/privacy/privacypolicy</argument>
                    </arguments>
                </block>
            </referenceBlock>
        </body>
    </page>

/view/frontend/layout/gdpr_privacy_privacypolicy.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>
      <referenceBlock name="page.main.title">
            <action method="setPageTitle">
                <argument translate="true" name="title" xsi:type="string">Privacy Policy</argument>
            </action>
        </referenceBlock>
        <referenceContainer name="content">
            <block class="Your\Modulename\Block\Account\PrivacyPolicy" name="gdpr.privacy.policy" template="Your_Modulename::account/customer_account.phtml" after="-" />
        </referenceContainer>
    </body>
</page>

/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 id="gdpr" frontName="gdpr">
            <module name="Your_Modulename" />
        </route>
    </router>
</config>

/Controller/Privacy/Privacypolicy.php

<?php
namespace Your\Modulename\Controller\Privacy;

use \Your\Modulename\Helper\Data;

class Privacypolicy extends \Magento\Framework\App\Action\Action
{
    protected $helperData;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        Data $helperData
    ){
        $this->helperData = $helperData;
        parent::__construct($context, $helperData);
    }   
  public function execute()
  {
    $resultRedirect = $this->resultRedirectFactory->create();

    if($this->helperData->isLoggedIn())
    {
        $this->_view->loadLayout();
        $this->_view->renderLayout();
    }
    else{
        $resultRedirect->setPath('customer/account/login/');
        return $resultRedirect;
    }
  }
}

/Helper/Data.php

<?php
    
    namespace Your\Modulename\Helper;
    
    use Magento\Framework\App\Helper\AbstractHelper;
    use Magento\Framework\App\Helper\Context;
    use Magento\Store\Model\ScopeInterface;
    
    class Data extends AbstractHelper
    {
    protected $context;
    
        public function __construct(
            Context $context,
            \Magento\Customer\Model\Session $customerSession)
        {
            $this->customerSession = $customerSession;
            $this->context = $context;
            parent::__construct($context);
        }
    // Check If Customer Login Or Not
        
        public function isLoggedIn()
        {
            return $this->customerSession->isLoggedIn();
        }
        
}

After then run below commands:-

php bin/magento s:up
php bin/magento s:s:d -f
php bin/magento c:c
php bin/magento c:f

And check OutPut:-

enter image description here

THANKS.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top