Setting 'h1' title on the Contact form in Magento 2
-
13-12-2020 - |
Domanda
I am trying to set a page title which is different to the <h1>
heading for my contact page, but there is a bug which does not let you use XML on the contact form, so I have included it in the <head>
tags.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Contact Us - Test</title>
<link rel="canonical" src="http://www.extenderstore.com.au/contact/" src_type="url"/>
</head>
<body>
<referenceContainer name="content">
<block class="Magento\Cms\Block\Block" name="contact-store-info" after="contactForm">
<arguments>
<argument name="block_id" xsi:type="string">contact_us</argument>
</arguments>
</block>
</referenceContainer>
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="wishlist_sidebar" remove="true" />
</body>
How can I have a page title of "Contact Us - Test" and an <h1>
heading of "Contact Us"?
Soluzione
You can use below code for h1 tag
<referenceBlock name="page.main.title">
<action method="setPageTitle">
<argument translate="true" name="title" xsi:type="string">Reach to Us</argument>
</action>
</referenceBlock>
Open your contacts_index_index.xml
file inside your layout folder and place this code above the body tag.
<head>
<title>Contact Form</title>
</head>
If above code does not work for you then do following.
This is a function under vendor/magento/module-contact/Block/ContactForm.php
It contains the following code:
/**
* @return $this
*/
protected function _prepareLayout()
{
$this->pageConfig->getTitle()->set(__('Contact Form'));
return parent::_prepareLayout();
}
Altri suggerimenti
Add to translation file {your_theme}/i18n/en_US.csv of Your theme string
"Contact Us","Contact Us - Test"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange