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– Dhiren Vasoya2018年09月11日 14:23:50 +00:00Commented Sep 11, 2018 at 14:23
-
Yes, the newsletter subscriptions page in the customer account frontendHowliee– Howliee2018年09月11日 14:26:15 +00:00Commented 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.Sukumar Gorai– Sukumar Gorai2018年09月11日 14:30:08 +00:00Commented Sep 11, 2018 at 14:30
-
How do I go about overriding the newsletter block?Howliee– Howliee2018年09月11日 14:31:17 +00:00Commented Sep 11, 2018 at 14:31
2 Answers 2
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>
You need to follow this step.
- create
newsletter_manage_index.xmlinto 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>
Explore related questions
See similar questions with these tags.