-1

I don't know how to add the sidebar.additional in the search page, can anyone help?

here's what i tried so far in catalogsearch_result_index.xml :

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
       <attribute name="class" value="page-products"/>
       
        <referenceContainer name="sidebar.additional">
            <block class="Magento\Framework\View\Element\Template" name="catalog.compare.sidebar"
                   template="Magento_Catalog::product/compare/sidebar.phtml">
                <arguments>
                    <argument name="jsLayout" xsi:type="array">
                        <item name="components" xsi:type="array">
                            <item name="compareProducts" xsi:type="array">
                                <item name="component" xsi:type="string">Magento_Catalog/js/view/compare-products</item>
                            </item>
                        </item>
                    </argument>
                </arguments>
            </block>
        </referenceContainer>
        
        <move element="sidebar.additional" destination="columns" />

    </body>
</page>

i basically want the same 3-columns layout that is in the category page: sidebar additional, columns with content and then the sidebar.main with the filters. can anyone help? i can only see the main column and the sidebar main...

2 Answers 2

0
  1. Create a Custom Module (if not already created)

Create the necessary directories and files for your custom module:

app/code/YourVendor/YourModule/etc/module.xml
app/code/YourVendor/YourModule/registration.php
app/code/YourVendor/YourModule/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="YourVendor_YourModule" setup_version="1.0.0"/>
</config>
app/code/YourVendor/YourModule/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'YourVendor_YourModule',
    __DIR__
);
  1. Define the Layout Update

Create a layout update file to add your custom block to the sidebar.additional section on the search results page:

app/code/YourVendor/YourModule/view/frontend/layout/catalogsearch_result_index.xml
app/code/YourVendor/YourModule/view/frontend/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>
        <referenceContainer name="sidebar.additional">
            <block class="Magento\Framework\View\Element\Template" name="your.custom.block" template="YourVendor_YourModule::custom.phtml"/>
        </referenceContainer>
    </body>
</page>
  1. Create the Template File

Create the template file that will be rendered by your custom block:

app/code/YourVendor/YourModule/view/frontend/templates/custom.phtml
app/code/YourVendor/YourModule/view/frontend/templates/custom.phtml

<div class="custom-sidebar-block">
    <h3>Custom Sidebar Block</h3>
    <p>This is a custom block added to the sidebar on the search results page.</p>
</div>
  1. Clear Cache and Deploy Static Content

After creating the necessary files, clear the cache and deploy the static content to see the changes:

php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:static-content:deploy -f
0

Try with the code below.

<?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>
        <referenceContainer name="sidebar.additional">
            <block class="Magento\Framework\View\Element\Template" name="catalog.compare.sidebar" template="Magento_Catalog::product/compare/sidebar.phtml">
                <arguments>
                    <argument name="jsLayout" xsi:type="array">
                        <item name="components" xsi:type="array">
                            <item name="compareProducts" xsi:type="array">
                                <item name="component" xsi:type="string">Magento_Catalog/js/view/compare-products</item>
                            </item>
                        </item>
                    </argument>
                </arguments>
            </block>
        </referenceContainer>

        <referenceContainer name="columns">
            <container name="div.sidebar.main" label="Sidebar Main" htmlTag="div" htmlClass="sidebar sidebar-main" before="-">
                <container name="sidebar.main" as="sidebar_main" label="Sidebar Main Content Container" htmlTag="div" htmlClass="sidebar sidebar-main-content">
                    <block class="Magento\Catalog\Block\Navigation" name="catalog.leftnav" template="Magento_Catalog::navigation/left.phtml" before="-"/>
                </container>
            </container>
        </referenceContainer>

        <move element="sidebar.main" destination="columns"/>

    </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.