How to give 2 different layout xmls within a single module. My module has one routes.xml with route_id='catalogsearch'

My folder structure:

Vendor\Module\Controller\Result\Index.php     //For CatalogSearch

Vendor\Module\Controller\Category\View.php     //For Catalog

So one of my overridden catalogsearch layout file is:


Now I want to override magento catalog module xml. Magento maintains the route name for catalog as 'catalog' itself.

Now how should I create a separate layout file for my custom module. Should it be: catalogsearch_category_view.xml?

If I had done like above, even if I search for keyword, in frontpage, I guess toolbar.phtml is calling, instead of catalog search.

My catalogsearch_result_index.xml (which seems to be fine):

<?xml version="1.0"?>
<referenceBlock name="catalogsearch.leftnav">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Vendor_Module::layer/view.phtml</argument>

UPDATED: My catalog_category_view.xml:

<?xml version="1.0"?>
<referenceBlock name="product_list_toolbar">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Vendor_Module::product/list/toolbar.phtml</argument>


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="catalogsearch" frontName="catalogsearch">
            <module name="Vendor_Module"/>


enter image description here

1 Answer 1


Your "catalogsearch_category_view.xm" file should be "catalog_category_view.xml".

I'm not sure if you need the routes.xml file. This file already exist in Magento_CatalogSearch module.

Your module should just inherit from magento's one.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Example_Module" setup_version="2.0.0" >
            <module name="Magento_Catalog"/>
            <module name="Magento_CatalogSearch"/>
  • IN catalog_category_view.xml, will the name 'catalog' be taken from magento's ? And are the contents of my catalog xml correct?
    – Sushivam
    Commented Jul 13, 2016 at 13:09
  • The content your file is correct. With catalog_category_view.xml you will override magento's category view. To modify the toolbar template i used : <referenceBlock name="product_list_toolbar" template="Example_Module::product/list/toolbar.phtml" />
    – Taschert
    Commented Jul 13, 2016 at 13:15
  • I have updated the answer ..could you please check why i get like this
    – Sushivam
    Commented Jul 13, 2016 at 13:19
  • You have no css, are your css files in pub/static/frontend/... ?
    – Taschert
    Commented Jul 13, 2016 at 13:21
  • Yes i have css in \Vendor\Module\view\frontend\web\css\mycss.cs
    – Sushivam
    Commented Jul 13, 2016 at 14:57

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.