1

I would like to edit the "General Subscription" text in my custom theme present in the My Account page under the Newsletter Subscription menu.

I've already located the page which is:

app/design/frontend/VENDOR/THEME_NAME/Magento_Customer/templates/form/newsletter.phtml

But I have no idea on how to create my custom module.

I've already created the registration.php and the module.php file.

but can you please explain me, what should I put in the layout folder? And also, what is the path of the templates folder? Just templates/form/newsletter.phtml?

Please, help me!

Thanks

2
  • Try using below way, it will definitely help you.... meetanshi.com/blog/…
    – nishu
    Commented Sep 27, 2019 at 4:45
  • Only for the text change don't override the template file. Add text in translation file in your theme. (EX. app/design/frontend/Test/Base/i18n/en_US.csv) Commented Aug 21, 2023 at 9:24

2 Answers 2

0

You can see the url like baseurl/newsletter/manage

so the xml file must be newsletter_manage_index.xml you can find this file from vendor/magento/module-newsletter/view/frontend/layout/newsletter_manage_index.xml

Override this file in you custom module

app/code/vendor/module/view/frontend/layout/newsletter_manage_index.xml with below code

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Customer\Block\Newsletter" name="customer_newsletter" cacheable="false" template="Vendor_Module::form/newsletter.phtml">
                <container name="customer.newsletter.form.before" as="form_before" label="Newsletter Subscription Form Before" htmlTag="div" htmlClass="rewards"/>
            </block>
        </referenceContainer>
    </body>
</page>

Default file's block doesn't have the template file path. It is declared in Magento\Customer\Block\Newsletter.php block file.

We have declared the custom phtml file path in xml as Vendor_Module::form/newsletter.phtml.

so copy the file from Vendor/module-customer/view/frontend/templates/form/newsletter.phtml to app/code/Vendor/Module/view/frontend/templates/form/newsletter.phtml

3
  • Thank you!! It worked like a charm :) Commented Sep 27, 2019 at 22:42
  • Np...please accept the answers if it is correct Commented Sep 28, 2019 at 1:27
  • Only for the text change don't override the template file. Add text in translation file in your theme. (EX. app/design/frontend/Test/Base/i18n/en_US.csv) Commented Aug 21, 2023 at 9:25
0

First you have to Override your Existing File so basically you need to follow such simple steps:

  1. Create Module OSCP_NewsletterOveride - Path: app/code/OSCP/NewsletterOveride
  2. Create module.xml file in path app/code/OSCP/NewsletterOveride/etc/module.xml

and paste this code

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="OSCP_NewsletterOveride" setup_version="1.0.0">
    </module>
</config>
  1. Create etc/registration.php file -path: app/code/OSCP/NewsletterOveride/registration.php

and paste this code

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'OSCP_NewsletterOveride',
    __DIR__
);
  1. Now Enable the Module with command:php bin/magento module:enable OSCP_NewsletterOveride

  2. This way you can create your Module.

Now Override Newsletter File

Create File URL/newsletter/edit/

Now Create newsletter_edit_index.xml in Path: app/code/OSCP/NewsletterOveride/view/frontend/layout/newsletter_edit_index.xml

and Add following code:

<?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">
    <update handle="customer_account"/>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Customer\Block\Newsletter" name="customer_newsletter_form" template="OSCP_NewsletterOverride::form/newsletter.phtml">
                <container name="customer.newsletter.form" as="form_override" label="Newsletter Subscription" htmlTag="div" htmlClass="newsletter_form"/>
            </block>
        </referenceContainer>
    </body>
</page>

Now copy your original newsletter file in following Path: app/code/OSCP/NewsletterOveride/view/frontend/templates/form/newsletter.phtml

Hope this will help you!!

2
  • Thank you. It worked, but with your xml file, it didn't override the previous one, but just added extra code to it. In order to make it work, I had to replace the form_override with form_before as @Ranganathan suggested :) Commented Sep 27, 2019 at 22:41
  • Only for the text change don't override the template file. Add text in translation file in your theme. (EX. app/design/frontend/Test/Base/i18n/en_US.csv) Commented Aug 21, 2023 at 9: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.