0

I am trying to change the title of the /newsletter/manage/ page. Can anyone guide me?

1 Answer 1

0

You can do that by overriding the \Magento\Newsletter\Controller\Manage\Index controller.

di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Newsletter\Controller\Manage\Index" type="Myvendor\Mymodule\Controller\Override\Manage\Index" />
</config>

\Myvendor\Mymodule\Controller\Override\Manage\Index class:

<?php
namespace Myvendor\Mymodule\Controller\Override\Manage;

class Index extends \Magento\Newsletter\Controller\Manage\Index
{
    public function execute()
    {
        $this->_view->loadLayout();

        if ($block = $this->_view->getLayout()->getBlock('customer_newsletter')) {
            $block->setRefererUrl($this->_redirect->getRefererUrl());
        }
        $this->_view->getPage()->getConfig()->getTitle()->set(__('[[My custom title]]'));
        $this->_view->renderLayout();
    }
}

Replacing the [[My custom title]] with your title

2
  • 1
    Thank you. I found a solution using the layout xml - app/design/frontend/FOLDER/THEMENAME/Magento_Contact/layout/contact_index_index.xml ... <body> <referenceBlock name="page.main.title"> <action method="setPageTitle"> <argument translate="true" name="title" xsi:type="string">Contact Us</argument> </action> </referenceBlock> ... Does either solution have an advantage over another? Jun 21, 2019 at 2:28
  • 1
    I think your solution is much better than mine :-)
    – NoamN
    Jul 29, 2019 at 7:26

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.