0

I need help to change the page title, the page is order details, I need to leave the page title dynamic, for each order to have its own, instead of showing increment id, I will show another attribute

I can change the title, but it always stays the same, as I did it by xml

my XML:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="page.main.title">
           <action method="setPageTitle">
              <argument translate="true" name="title" xsi:type="string">Custom Title</argument>
           </action>
        </referenceBlock>
        
    </body>
</page>

how do I change this via controller, or observer, to be dynamic?

1 Answer 1

1

You can do it in your Block file, open relevant block file and use this code:

$this->pageConfig->getTitle()->set("Your custom dynamic title");

where $this->pageConfig is the instance of \Magento\Framework\View\Page\Config

You can use this code in __consturct function or _prepareLayout function

Hope this will help you.

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.