2

Ok, this sounds like it should be really simple but its driving me crazy. All I want to do is change the title above the Newsletter subscribe form in the footer of Magento 2. I have a child theme of Luma.

I thought I could just copy module-newsletter from vendor/magento/module-newsletter in to my theme directory and it would override. But this doesn't seem to be the case. There must be a way of altering the /vendor/magento/module-newsletter/view/frontend/templates/subscribe.phtml file from my child theme?

1

at your theme directory and the file path

 design/frontend/Vendor/themename/Magento_Newsletter/templates/subscribe.phtml

Vendor: the first char Uppercase

themename: lowercase

0

Create a module and rewrite subscribe class

app/code/Namespace/Modulename/etc/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\Block\Subscribe" type="Namespace\Modulename\Block\Subscribe"/>  
</config>

Block file app/code/Namespace/Modulename/Block/Subscribe.php as below

<?php

namespace Namespace\Modulename\Block;

use Magento\Framework\View\Element\Template;


class Subscribe extends Template
{

    public function __construct(Template\Context $context,array $data = [])
    {
        parent::__construct($context, $data);
    }


    public function beforeToHtml(\Magento\Newsletter\Block\Subscribe $originalBlock)
    {
        $originalBlock->setTemplate('Namespace_Modulename::subscribe.phtml');
    }    

}

your phtml file app/code/Namespace/Modulename/view/frontend/templates/subscribe.phtml

0

You don't need to create any custom module for overriding phtml file. All you need to do is override the file in your theme at this location

app/design/frontend/[VENDOR NAME]/[THEME NAME]/Magento_Newsletter/templates/subscribe.phtml

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.