0

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.

1 Answer 1

2

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.

0

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.