Magento 2 Customize the search result
With Advanced Content Manager for Magento 2, it’s possible to index and make your content searchable.
The default catalog search layout is overridden by our extension, in order to add our results to the search.
The extension is adding a Result Search Block into the Catalog Search Result page layout:
Samdoit/ContentManager/view/frontend/layout/catalogsearch_result_index.xml
<page xmlns:xsi="..." layout="2columns-left" xsi:noNamespaceSchemaLocation="...">
<body>
<referenceContainer name="content">
<block class="Samdoit\ContentManager\Block\Search\Result" name="search.content.result" after="search.result" template="Samdoit_ContentManager::content/search/result.phtml" cacheable="false">
<referenceContainer>
<body>
<page>
The Result Block retrieves the current query and create the search filter. The block will load a ContentList Collection from the ids retrieved in the results.
This block has the following child:
<block class="Samdoit\ContentManager\Block\Content\Widget\ContentList" name="search_content_result_list" template="Samdoit_ContentManager::content/widget/list.phtml" cacheable="false"> <block>
This child block is nothing else that a ContentList widget. See the following documentation to customize the content list widget: XML layout
Then if you want to customize the result search for the content, you should override the following layout in frontend:
catalogsearch_result_index.xml
Be sure that the Blackbird_ContentManager module is loaded before yours. You can add the instruction in your module.xml file:
<module name=”Samdoit_ContentManager” setup_version=”1.0.0”>
<sequence>
<module name=”Samdoit_ContentManager”/>
<sequence>
<module>
Now, in your catalogsearch_result_index.xml file, paste the following code in the tags and add instructions from the following resource: XML layout update
<referenceBlock name=”search_content_result_list” template=”my_custom_template.phtml”> <referenceBlock>
However if you just want to modify the template of the result search, see the following resource: Overriding templates