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;
    }

}

3 Answers 3

7

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 Commented Jan 2, 2019 at 6:25
  • @Rahul Singh added another solution
    – fmsthird
    Commented Jan 2, 2019 at 6:33
  • changed $this->resultPageFactory->create() to $this->resultFactory->create(ResultFactory::TYPE_PAGE), after that it worked. Thanks Commented Jan 2, 2019 at 6:41
  • yeah! that's great!
    – fmsthird
    Commented Jan 2, 2019 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
    Commented Mar 12, 2020 at 7:28
1

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;
                }
1

Try this within body tag of your layout file

view/adminhtml/layout/id_foldername_classname.xml

<body>
        <referenceBlock name="page.title">
            <action method="setPageTitle">
                <argument name="title" xsi:type="string">Greetings</argument>
            </action>
        </referenceBlock>
</body>

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.