Web Analytics

Fill the form & Get Installation Support

How to Override Block in Magento 2

Configure Module

Create module.xml at app/code/Magemonkeys/RewriteContact/etc and add the following code inside it:

Override di.xml File

Now, I will override di.xml file. Create di.xml at app/code/Magemonkeys/RewriteContact/etc and add following code in the dl.xml file.

Override Contact Form

It’s time to override contact form. Create ContactForm.php at app/code/Magemonkeys/RewriteContact/Block and add following code in this newly created file:

Override contact_index_index.xml

Create contact_index_index.xml at app/code/Magemonkeys/RewriteContact/view/frontend/layout and add following code in this file:

Override form.phtml

Go to vendor/magento/module-contact/view/frontend/templates from the root directory of your store and copy the form.phtml file to app/code/Magemonkeys/RewriteContact/view/frontend/templates folder.

Now, you just need to update the form.phtml by adding following code:

I have added <?php echo $block->getText(); ?>  under <div class=“field note no-label”>  in order to display it in a clear and decent format.

Run Commands

Go to the root directory of your store and run the following commands:


Launch your store and go to the contact form.  You will see the desired result as below:

Are you having any query with your Magento store?
Fill the form below to hire Magento expert(s).
Fill the below form if you have any Magento programming need.

    Recent Articles

    Author Info

    Author Image

    Magento Certified Developer

    Hire J. Lakum

    Get a Free Quote

      /* second popup */

      Connect With Us