3

I have created a custom module using UI_COMPONENT. Everything worked properly, but unable to set the Page Title.

enter image description here

Index layout file:

<?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">
    <head>
        <title>Test</title>
    </head>
    <body>
        <referenceContainer name="content">
            <uiComponent name="testing_item_grid"/>
        </referenceContainer>
    </body>
</page>

Adding Solution: In Adminhtml Controller prepend your title text.

Here is the code:

namespace Testing\test\Controller\Adminhtml\Index;
use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action;
class Index extends Action{
    public function execute() {

        $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
        $resultPage->getConfig()->getTitle()->prepend(__(" Custom Grid"));
        return $resultPage;
    }

}
5

just go to your module's adminhtml index layout and set your title inside head tag:

<head>
    <title>
        Your title goes here...
    </title>
</head>

or try prepend(__("Title"));

public function execute()
{
    $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
    $resultPage->getConfig()->getTitle()->prepend(__(" Custom Grid"));
    return $resultPage;
}
6
  • already head is there, but it not showing – Rahul Singh Jan 2 '19 at 6:25
  • @Rahul Singh added another solution – fmsthird Jan 2 '19 at 6:33
  • changed $this->resultPageFactory->create() to $this->resultFactory->create(ResultFactory::TYPE_PAGE), after that it worked. Thanks – Rahul Singh Jan 2 '19 at 6:41
  • yeah! that's great! – fmsthird Jan 2 '19 at 6:44
  • 1
    try to add below code inside layout file <referenceBlock name="page.title"> <action method="setPageTitle"> <argument translate="true" name="title" xsi:type="string">Your Page Title</argument> </action> </referenceBlock> – Nilu Khair Mar 12 '20 at 7:28
0

enter image description here

You can update code into your grid controller & change title whatever you want.

use Magento\Framework\View\Result\PageFactory;

 protected $resultPageFactory;

    public function __construct(
            Context $context,
            PageFactory $resultPageFactory,

        ) {
            parent::__construct($context);
            $this->resultPageFactory = $resultPageFactory;

        }
            public function execute()
                {
                    /** @var \MAgento\Backend\Model\View\Result\Page $resultPage */
                    $resultPage = $this->resultPageFactory->create();
                    $resultPage->getConfig()->getTitle()->prepend(__('Dealer Settlement Report
        '));
                    return $resultPage;
                }

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.