0

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:

catalogsearch_result_index.xml

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>
    </action>
</referenceBlock>

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>
    </action>
</referenceBlock>

routes.xml:

<?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"/>
        </route>
    </router>
</config>

UPDATED:

enter image description here

1 Answer 1

0

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" >
        <sequence>
            <module name="Magento_Catalog"/>
            <module name="Magento_CatalogSearch"/>
        </sequence>
    </module>
</config>
8
  • IN catalog_category_view.xml, will the name 'catalog' be taken from magento's ? And are the contents of my catalog xml correct?
    – Sushivam
    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
    Jul 13, 2016 at 13:15
  • I have updated the answer ..could you please check why i get like this
    – Sushivam
    Jul 13, 2016 at 13:19
  • You have no css, are your css files in pub/static/frontend/... ?
    – Taschert
    Jul 13, 2016 at 13:21
  • Yes i have css in \Vendor\Module\view\frontend\web\css\mycss.cs
    – Sushivam
    Jul 13, 2016 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.