Domanda

I am using Magento 2.3.5 and I need to call custom block before layered navigation. How can I call that?

I used this below code

<?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.main">
            <block class="Magento\Framework\View\Element\Template" name="my_block" as="my_block" template="Vendor_Module::test.phtml" before="-"/>
        </referenceContainer>
    </body>
</page>

But, it's call after layered navigation. How to call my block before layered navigation. (sidebar main class)

Any help would be appreciated.

Thanks.

È stato utile?

Soluzione

You need to move your block after catalog.leftnav. Just copy this below code and replace in your xml file

app/code/Vendor/Module/view/frontend/layout/default.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.main">
            <block class="Magento\Framework\View\Element\Template" name="my_block" as="my_block" template="Vendor_Module::test.phtml" before="-"/>
        </referenceContainer>
        <move element="catalog.leftnav" destination="sidebar.main" after="my_block" />
    </body>
</page>

Clean cache and check it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top