To call the layered navigation I use this call and it worked

<?php echo $block->getLayout()->getBlock('catalog.leftnav')->toHtml();?>  

For remove it I use this in default.xml

<reference block name="catalog.leftnav" remove="true" />

But when I remove this above calling code fails because of what I do.

4 Answers 4


As far as I know, that is impossible to remove your block (which is called directly on your phtml) by using layout xml. We can try two options:

  1. We can set this block in your xml also. And, then remove it via layout.

  2. Try to add conditions for this block: when it shows or not.

  • I am not getting u proper
    – Devendra
    Sep 15, 2016 at 14:00
  • No read my question
    – Devendra
    Sep 15, 2016 at 14:09
  • You tried to remove this line code: <?php echo $block->getLayout()->getBlock('catalog.leftnav')->toHtml();?>, but you failed? Sep 15, 2016 at 14:12
  • No second code to remove i used
    – Devendra
    Sep 15, 2016 at 14:21
  • <?php echo $block->getLayout()->getBlock('catalog.leftnav')->toHtml();?‌​> when calling this way, we cannot remove it via layout xml <reference block name="catalog.leftnav" remove="true" />. My answer was for this case. Sep 15, 2016 at 14:41

Well you have a typo there:


Instead of leftnavv that should be leftnav.

  • No it mt editing mistake u suppose catalog.leftnav on both code
    – Devendra
    Sep 15, 2016 at 13:30
  • In which phtml file are you calling this?
    – ps202
    Sep 15, 2016 at 13:43
  • i want call layered navigation in list.phtml file
    – Devendra
    Sep 15, 2016 at 13:44
  • Well I think you should create your own theme with your own layout and put the block whererwere you want. devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…
    – ps202
    Sep 15, 2016 at 15:36

I believe you have a typo. It should be:

<referenceBlock name="catalog.leftnav" remove="true" />

Change your code:

<?php echo $block->getLayout()->getBlock('catalog.leftnav')->toHtml();?>  

to this:

<?php echo $block->getChildHtml('catalog.leftnav') ?>

and on your custom theme file called default.xml you will need to complement with this block.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="sidebar.main">
            <block class="Magento\Catalog\Block\Navigation" name="catalog.leftnav" before="-" template="navigation/left.phtml"/>

Change the referenceContainer named sidebar.main

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.