1

I've created a simple module, purely for the block.

I want to add it to the newsletter.phtml file that controls the customers newsletter subscriptions as I need to create custom functionality through my block.

How do I go about adding my custom block to this file or any file?

I'm new to this whole module development, any help would be appreciated.

  • You want to add your custom block to newsletter section, right? – Dhiren Vasoya Sep 11 '18 at 14:23
  • Yes, the newsletter subscriptions page in the customer account frontend – Howliee Sep 11 '18 at 14:26
  • You can override the newsletter block then you can customize it according to your requirement also you can add more public functions to your block which can be used in your newsletter phtml. – Sukumar Gorai Sep 11 '18 at 14:30
  • How do I go about overriding the newsletter block? – Howliee Sep 11 '18 at 14:31
0

You may be want to remove Magento default newsletter . Then you there are two steps need to call for all your block.

Create newsletter_manage_index.xml at your module folder app/code/{Vendor}/{ModuleName}/view/frontend/{layout}/

<?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">
    <body>
    <!-- remove defult block -->
       <referenceBlock name="customer_newsletter" remove="true" />

        <referenceContainer name="content">
            <block class="{Vendor}\{ModuleName}\Block\{YourClassName}" name="customer_newsletter_new" cacheable="false" template="Magento_Customer::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>
0

You need to follow this step.

  1. create newsletter_manage_index.xml into your custom extension with the code something like this.

app/code/Vendor/Extension/view/frontend/layout/newsletter_manage_index.xml

<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="Vendor\Extension\Block\Yourblock" name="custom_newsletter" template="Vendor_Extension::yourphtmlfile.phtml" />
        </referenceContainer>
    </body>
</page>

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.