I want to move the 'Did you mean' and 'Related serch terms' section to sidebar in the catalog search Page in Magento 2. currenty that both sections are appeared in 'search results' div. The 'sidebar sidebar-main' is appeared but empty. My layout is 2columns-left. Help me to solve this .
1 Answer
div.sidebar.main
container responsible for the sidebar sidebar-main
div.
Depending on your need, you can create catalogsearch_result_index.xml
file in your module or your theme.
- If you choose put this file in your module, the file path should be:
app/code/YourVendor/YourModule/view/frontend/layout/catalogsearch_result_index.xml
- If you choose put this file in your theme, the file path should be:
app/design/frontend/YourThemeVendor/YourTheme/Magento_CatalogSearch/layout/catalogsearch_result_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="search_suggestions" destination="div.sidebar.main"/>
<move element="search_recommendations" destination="div.sidebar.main"/>
</body>
</page>
Remember to clear layout
cache type.
-
Thanks it works. Could you tell me . how do you find the element name like "search_suggestions" and "search_recommendations". I have struggled to find out. once again thanks a lot. Commented Jan 2, 2023 at 15:39
-
Glad to help you out! Sure. 1st step: search for "Did you mean" in vendor/magento, you will know that these words come from Magento_AdvancedSearch module. 2nd step, as catalogsearch_result_index.xml layout file responsible for the catalog search result page, go to Magento_AdvancedSearch's layout folder (vendor/magento/module-advanced-search/view/frontend/layout) to open catalogsearch_result_index.xml to check blocks. Let me know if you need any further assistance.– Tu VanCommented Jan 2, 2023 at 15:54
-
Great explanation. Thanks . This will really help me a lot for my future development. Commented Jan 2, 2023 at 16:44
-
If you like to learn more other parts of Magento 2, you can take a look at my answers in other posts. Most of my answers are explain in details and have step by step instructions, I’m sure you will find it helpful: magento.stackexchange.com/users/39884/…– Tu VanCommented Jan 2, 2023 at 16:48