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.

asked Sep 11, 2018 at 14:20
4
  • You want to add your custom block to newsletter section, right? Commented Sep 11, 2018 at 14:23
  • Yes, the newsletter subscriptions page in the customer account frontend Commented Sep 11, 2018 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. Commented Sep 11, 2018 at 14:30
  • How do I go about overriding the newsletter block? Commented Sep 11, 2018 at 14:31

2 Answers 2

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>
answered Sep 11, 2018 at 14:34
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>
Abhishek Panchal
4,9643 gold badges22 silver badges39 bronze badges
answered Sep 11, 2018 at 14:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.