how can customize or overwrite the catalogsearch_result_index.xml template for add my own block?
Create a layout with the same (catalogsearch_result_index.xml
) file name in your extension, and then use the referenceBlock
or referenceContainer
predicate.
I created this file
app/code/Namespace/Module/view/frontend/layout/catalogsearch_result_index.xml
with this content
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="search.result">
<block class="Magento\Framework\View\Element\Text" name="foo">
<action method="setText">
<argument name="text" xsi:type="string">
<![CDATA[<p>This is my own message</p>]]>
</argument>
</action>
</block>
</referenceBlock>
</body>
</page>
and I modified this file too
app/code/Namespace/Module/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Namespace_Module" setup_version="1.0.1">
<sequence>
<module name="Magento_CatalogSearch"/>
</sequence>
</module>
</config>
but it’s not OK
What did I do wrong?
What exact state of the system you have denoted by the term “not OK”?
when I search I see that does not display the message.
Is your extension loaded by the system?
yes
The search.result
block uses the result.phtml
template:
The result.phtml
template does not render arbitrary children blocks:
But it calls the getAdditionalHtml()
method:
So if add your block as a child of the search_result_list
block, then it will be rendered.
The core itself uses it, for example, to render a toolbar: