3

As far as I can tell Magento2 is not working as expected here.

In /Magento_CatalogSearch/layout/ I have 4 XML files:

catalogsearch_advanced_index.xml
catalogsearch_advanced_results.xml
catalogsearch_result_index.xml
default.xml

In the top of each of these files I have the following line:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

Notice it says layout="1column". I have cleared caches, I have re-indexed.

Despite all of this my search results page is still using 2columns-left.

My search results page is using 2columns-left as its template file. How do I change this so my search results page is using 1column?

Here is the full contents of catalogsearch_result_index.xml:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <attribute name="class" value="page-products"/>
        <referenceContainer name="content">
            <block class="Magento\CatalogSearch\Block\Result" name="search.result" template="result.phtml" cacheable="false">
                <block class="Magento\CatalogSearch\Block\SearchResult\ListProduct" name="search_result_list" template="product/list.phtml" cacheable="false">
                    <arguments>
                        <!-- If argument's position depends on image size changeable in VDE:
                        positions:list-secondary,grid-secondary,list-actions,grid-actions,list-primary,grid-primary
                    -->
                        <argument name="positioned" xsi:type="string">positions:list-secondary</argument>
                    </arguments>
                    <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="product/list/toolbar.phtml" cacheable="false">
                        <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager" cacheable="false"/>
                    </block>
                    <action method="setToolbarBlockName">
                        <argument name="name" xsi:type="string">product_list_toolbar</argument>
                    </action>
                    <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                        <block class="Magento\Framework\View\Element\Template" as="default"/>
                    </block>
                </block>
                <action method="setListOrders"/>
                <action method="setListModes"/>
                <action method="setListCollection"/>
            </block>
        </referenceContainer>
    </body>
</page>
9
  • Have you clear cache? Commented Apr 22, 2016 at 10:29
  • several times, and ive re-indexed
    – Jimmery
    Commented Apr 22, 2016 at 10:30
  • plz show your catalogsearch_result_index.xml file content. catalogsearch_result_index.xml is responsible for result page. Commented Apr 22, 2016 at 10:32
  • This file from theme or core module files? Commented Apr 22, 2016 at 10:44
  • @Rakesh done that - I havent changed this file much tbh
    – Jimmery
    Commented Apr 22, 2016 at 10:45

3 Answers 3

1

In catalogsearch_result_index.xml use <update handle="1column"/> after <layout> start.

So it should be like this

<body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd"> 
<update handle="1column"/>........your other codes

Clear cache, deploy static files and check

8
  • when you put <layout xmlns:xsi="... did you mean to put <body xmlns:xsi="... or are you suggesting that I should change body to layout?
    – Jimmery
    Commented Apr 22, 2016 at 10:42
  • 2
    ok, putting <update handle="1column"> directly after the <body> tag results in the page being completely blank?
    – Jimmery
    Commented Apr 22, 2016 at 10:48
  • 1
    You forgot the closing / @jimmery
    – Ben Crook
    Commented Jun 23, 2016 at 6:41
  • 1
    Has this been the correct answer? If so, take your time, and accept! Help others to find answers quickly trough that.
    – Max
    Commented Oct 11, 2016 at 13:26
  • 2
    How do you use 1-column layout only for "no results" and keep 2-column for when there are results?
    – thdoan
    Commented Mar 7, 2017 at 8:48
13

You have to just add below file inside app/design/frontend/{Package}/{themename}/Magento_CatalogSearch/ content for catalogsearch_result_index.xml

 <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    
    </page>

Flush the cache php bin/magento cache:flush

3
  • plz check using above working code. Commented Apr 22, 2016 at 10:58
  • 1
    this is what I already have, as stated in my question - and it doesnt work
    – Jimmery
    Commented Apr 22, 2016 at 11:31
  • This works for Magento 2.4.2, hint: make sure that you are using 1column not 1-column
    – Black
    Commented Feb 12, 2021 at 16:03
2

I'm putting this here since it essentially provides the intended result, even though it doesn't do it the perfect way. Changing the layout attribute or using a update handle (mentioned in previous examples) of Magento_CatalogSearch/layout/catalogsearch_result_index.xml did not actually change the layout of the page as you can confirm by checking the body class. I would love to know why this isn't working since the same approach works in other modules. It could be something on my installation, but judging by the other responses here it could be something else.

If you target the Main Sidebar you can essentially achieve the desired 1column layout.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="sidebar.main" remove="true" />
    </body>
</page>

My page element layout attribute is set to "1column" here, but through testing it is being ignored.

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.