0

I want to change page title in child theme for contact-us page. But when I'm trying to override file Magento_Contact/templates/form.phtml in my child theme from parent theme then on frontend the page showing blank. I also copied layout/contact_index_index.xml and all other templates too, still template file overridden not working.

How do I override Magento_Contact/templates/form.phtml?

My Parent theme contact_index_index.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Contact Us</title>
    </head>
    <body>
        <referenceContainer name="page.top">
            <block class="Namespace\Theme\Block\Template" name="google_map" template="Magento_Contact::google_map.phtml"/>
        </referenceContainer>
        <referenceContainer name="content">
            <block class="Namespace\Theme\Block\Template" name="contactPage" template="Magento_Contact::contact_page.phtml">
                <block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml">
                    <container name="form.additional.info" label="Form Additional Info"/>
                </block>
            </block>
        </referenceContainer>
    </body>
</page>

2 Answers 2

2

You need to do following things.

create contact_index_index.xml at following location.

app/design/frontend/[vendor]/[Your Theme]/Magento_Contact/layout/contact_index_index.xml

with this code

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
   <body>
        <referenceBlock name="contactForm">
           <action method="setTemplate">
                <argument name="template" xsi:type="string">Magento_Contact::form.phtml</argument>
            </action>
        </referenceBlock>
   </body>
</page>

Now create form.phtml at following location.

app/design/frontend/[vendor]/[Your Theme]/Magento_Contact/templates/form.phtml

Now modify phtml file according to your requirement.

3
  • I tried, but still getting blank page if override. If layout file is in parent theme then it is required to override in child theme too? Commented Mar 12, 2018 at 13:54
  • Have you run deploy command after this? also run caching command as well. Commented Mar 12, 2018 at 14:21
  • Yes, after deploy command, override file changes showing on frontend. Commented Mar 13, 2018 at 4:07
0

Just overrride the contact_index_index.xml file in your theme by copying the below code at path - app/design/frontend/packagename/themename/Magento_Contact/layout

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>

            <!-- and for the page title: -->
            <referenceBlock name="page.main.title">
               <action method="setPageTitle">
                  <argument translate="true" name="title" xsi:type="string">Your new title</argument>
               </action>
            </referenceBlock>

    </body>
</page>

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.